Tuesday, March 13, 2012

setting the value of a variable from another page

I want to set the value of string variable in my usercontrol. The masterpage uses the user control and I have a .aspx file in which the page load is suppose to set the variable in the usercontrol.

I have in my page load of the .aspx page to:

((Usercontrol)Master.FindControl("navigation").setCurrent = "on";

_setCurrent is the variable name in the user control.

In the user control i have a get/set property

public string setCurrent

{

return _setControl;

}

set

{

_setControl = value;

}

}

I cant seem to figure out how to set that stupid variable to what my aspx page sets it to. Am I doing something wrong? Thanks!

Try this

((<your user control class name>)Master.FindControl("navigation")).setCurrent = "on";

Hope this helps..


my user control is called mainNav, and when i changed it from UserControl to mainNav, it complains that the namespace could not be found. Can you guide me a bit? Thanks.

Hi, unlike ASP.NET 1.x, the compilation model of ASP.NET 2 is a bit different, in which the web forms and user control will be compiled into their own single assembly. This is why the class not found even in the same namespace.

Try to see myprevious post, see whether i helps..

0 comments:

Post a Comment