tags:

views:

179

answers:

1

I'm using ASP.Net 2.0. I have a custom control that is inherits from a 3rd-party vendor's control. I'm trying to override the Render method.

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
 if (some condition is true) then    
   Dim d As New Button()    
   d.RenderControl(writer)    
 else    
   MyBase.Render(writer)    
 end if    
end sub

What I need is that under certain situations I want to be able to render a Button instead of the original control. But I want the Button to have the same client Id as the control so that I can use javascript to manipulate it.

How do I assign a clientid to the button? Thank you.

+1  A: 

ClientID is based on the control's ID and UniqueID of its parent. When you create your button you should give it an ID. I don't see that happening in your code. After you Dim it, use d.ID="btnIdNameHere"

From MSDN:

The ClientID value is generated by concatenating the ID value of the control and the UniqueID value of its parent control. If the ID value of the control is not specified, an automatically generated value is used.

Ahmad Mageed
Using d.ID="btnIdNameHere" doesn't work for me because my control is in a panel. It can also be in multiple nested panels.So when I create the button I can't seem to make it such that it is the same ID as my original control.
janem