GibbsUSA.net Blogs  

Tuesday, February 07, 2012

 Logon   Blogs Home   GibbsUSA.net Home  


Personal blog for C#- Real problems- Real solutions!   

Search:

Archives
 Home... 
 May 2008 (1) 
 August 2007 (2) 
 December 2006 (1) 
 October 2006 (5) 
 
8/15/2007 8:23 AM:  Client JavaScript and .NET Server Controls

GibbsUSA.net smilie: grim The new .NET model renames the server controls dynamically, giving them a unique ID. See below for an example.

The following is the control on the ASPX page designer:
<asp:CheckBox id=chkBInfo runat=server checked=true/>

This is rendered to the client in HTML as:
<input id="ctl00_ContentPlaceHolder1_chkBInfo" type="checkbox" name="ctl00$ContentPlaceHolder1$chkBInfo" checked="checked" />

As you can see, the controls name cannot be determined easily...or can it???

Well, so long as your JavaScript remains on the same ASPX page, you can get the control using "ClientID":
function theForm_onSubmit(){
if (document.forms(0).<%=chkBInfo.ClientID%>.checked==false)
{
alert('Please select a Message Type...');
return false;
}
}

Hope this helps!!! GibbsUSA.net smilie: coolguy


Comments (0) >>> Print >>> EMail >>>

8/14/2007 11:16 AM:  Add a CSS header dynamically...

GibbsUSA.net smilie: smile With the increased use of Master pages etc, I had the need to add the CSS stylesheet dynamically depending on the situation.

Putting the following code in the Page_Load event of the individual page solved the problem:


// add the stylesheet..
HtmlHead myHeader = (HtmlHead)this.Page.Header;
if (theHeader != null)
{
HtmlLink myCSS = new HtmlLink();
myCSS.Attributes.Add("href", "admin/td_codes.css");
myCSS.Attributes.Add("rel", "stylesheet");
myCSS.Attributes.Add("type", "text/css");
theHeader.Controls.Add(myCSS);
}


Comments (0) >>> Print >>> EMail >>>

 

Join Chris on Facebook 
CLR v2.0.50727.3625


Please see the site Terms And Conditions and the site Privacy Statement.
This entire web site (and the software contents therein) is Copyright © Chris Gibbs 2000-2012.
Any reproduction or copying is expressly forbidden without the prior consent of Chris Gibbs.
For more information, please contact the site WebMaster (WebMaster@GibbsUSA.net).