Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 28, 2013 08:21 AM by AidyF
Member
258 Points
168 Posts
Feb 27, 2013 03:20 PM|LINK
Im on the PageLoad of one of my pages and trying to reference a div in the Site.Master ...
HtmlGenericControl divSessionExpirationPopUp = (HtmlGenericControl)Master.FindControl("divSessionExpirationPopUp");
The above reference doesn't work, how should I reference the div so i can use it in code?
<body onhelp="return false;" onkeydown="ByPass();" > <div id='divSessionExpirationPopUp' style='position: absolute; z-index: 10000; height: 300px; width: 100%; left: 70px; top: 250px; display: none;'>
Star
9250 Points
1578 Posts
Feb 27, 2013 03:25 PM|LINK
You can only find server-side controls with FindControl. Add the runat="server" tag to your div, but note that the rendered ID might change which might affect your javascript or css.
All-Star
41188 Points
6034 Posts
Feb 27, 2013 03:29 PM|LINK
Yes, Control need runat="sever" attribute, for accessing it from codebhind.
chjones2008 HtmlGenericControl divSessionExpirationPopUp = (HtmlGenericControl)Master.FindControl("divSessionExpirationPopUp");
var divSessionExpirationPopUp = Master.FindControl("divSessionExpirationPopUp");
Feb 27, 2013 04:12 PM|LINK
Thanks, fixed my problem, I have javascript code and fixed the names.
Feb 28, 2013 08:21 AM|LINK
If your JS is on the aspx/acsx page itself you can get the ID dynamically using
var id = '<%= ServerControlID.ClientID %>';
chjones2008
Member
258 Points
168 Posts
Cast Div Object
Feb 27, 2013 03:20 PM|LINK
Im on the PageLoad of one of my pages and trying to reference a div in the Site.Master ...
HtmlGenericControl divSessionExpirationPopUp = (HtmlGenericControl)Master.FindControl("divSessionExpirationPopUp");AidyF
Star
9250 Points
1578 Posts
Re: Cast Div Object
Feb 27, 2013 03:25 PM|LINK
You can only find server-side controls with FindControl. Add the runat="server" tag to your div, but note that the rendered ID might change which might affect your javascript or css.
budugu
All-Star
41188 Points
6034 Posts
Re: Cast Div Object
Feb 27, 2013 03:29 PM|LINK
Yes, Control need runat="sever" attribute, for accessing it from codebhind.
var divSessionExpirationPopUp = Master.FindControl("divSessionExpirationPopUp");"Don't be afraid to be wrong; otherwise you'll never be right."
chjones2008
Member
258 Points
168 Posts
Re: Cast Div Object
Feb 27, 2013 04:12 PM|LINK
Thanks, fixed my problem, I have javascript code and fixed the names.
AidyF
Star
9250 Points
1578 Posts
Re: Cast Div Object
Feb 28, 2013 08:21 AM|LINK
If your JS is on the aspx/acsx page itself you can get the ID dynamically using