Scope of a variable on designer page

Commonly, if we want to code on our designer page[aspx], we should be aware about the scope of a variables on the same.

Once, I wanted to show same information on more than one place, I used variable but after a long research i came to know that “VARIABLE SCOPE IS DEVIDED AS PER SECTION HAVING RUNAT=’SERVER’ ON THE DESIGNER PAGE.”.

Please make sure if you want to use common varibles, use them within same block having runat=’server’.

Feel free to clear your doubts –> me@anoopkumarsharma.com

  1. I faced a problem that I was not able to access a variable in the head section of my aspx page. Can you help?

  2. Yes Aarti. Please note that variable scope is maintained as per their blocking defined by runat=server . so if you want to access same variable on head please make sure that all related sections should be in same runat=server block.

    Better to control your head section from your code behind or from body section of designer.

  3. Thanks it worked

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>