BLOGS BY TOPIC
BLOGS BY AUTHOR
BLOGS BY YEAR
Posted by Andy Brown on 10 October 2011
You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Use ClientIdMode to Refer to ASP.NET Controls as HTML
Consider the following web server control in ASP.NET:
A typical ASP.NET textbox control
By default, this is how this renders as HTML:
How this textbox would render in HTML
The page on which the control sits uses a master page, and the cph stands for ContentPlaceHolder.
The question is: how could you refer to this textbox in client script, when you don't know how its name will be constructed?
The answer is to use the web server control's ClientIdMode property:
The four possible values for this property
To see how this property works, the best two websites that I could find were these:
|Dan Maharry's blog||Once you can get over the black background and difficult-to-read font, this gives an excellent summary of the possible property values above.|
|Rick Strahl's blog||With a more orthodox appearance, this blog summarises the property values in slightly less detail.|
Typical times when you might want to reference the client id property of a control are:
- when you want to set the DefaultButton property of a form;
- when you want to apply the Focus method to a control to make it the active one;
- when you want to use RegisterClientScriptBlock to attach client script to a form, which in turn should reference a particular control.
And since our youngest daughter has just come into the room I'm working in and started playing the piano, perhaps it's time to end there!