Add a link to any widget

Source: Internet
Author: User
One requirement today is to create a custom server control that requires the control to have a url attribute. All the controls placed in the control can have the ability of Url redirection.
In the beginning, we implemented the "output. addAttribute (HtmlTextWriterAttribute. href, "www.163.com", but this method has some disadvantages, that is, the control needs to be rewritten. In this case, the original attributes of some controls are lost. If MyBase is used. if the Render (output) is not rewritten, the image control will not be able to add the steering attribute, which I am confused about, is it because the layer is formed in the middle.
The final code is as follows:
Imports System. Web. UI
Imports System. Drawing
Imports System
<ToolboxData ("<{0}: Link runat = server> </{0}: Link>")> Public Class Link
Inherits System. Web. UI. WebControls. Panel
Implements INamingContainer
Private _ Url As String = String. Empty
Property Url () As String
Get
Return _ Url
End Get
Set (ByVal Value As String)
_ Url = Value
End Set
End Property
Protected Overrides Sub Render (ByVal output As System. Web. UI. HtmlTextWriter)
Output. WriteBeginTag ("")
Dim fulltest As String = "javascript: window. open ('" & _ Url &"');"
Output. WriteAttribute ("onclick", fulltest)
Output. WriteAttribute ("href ","#")
MyBase. Render (output)
Output. WriteEndTag ("")
End Sub
End Class
In this way, any control that is dragged into this control has the steering attribute, and the control itself remains intact.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.