I have a variable that is declared in a user control. It is the value of a drop down list in the user control. When I try to use it in an If statement on an aspx page it says that the variable is not declared. Is there a way to declare the variable
on the aspx page or make it recognize that it is declared on the user control page? I'm calling the code at the top of the aspx page <%@ Register src="pType.ascx" tagname="pType" tagprefix="uc2" %> I'm using the if statement <%If pt.SelectedValue = "1" Then%> \\do things <%End If%> In the control pt is defined by <asp:DropDownList ID="pt" runat="server"> Thank you!
hugandboo
0 Points
1 Post
User control variable not declared
Feb 21, 2013 12:36 AM|LINK
I have a variable that is declared in a user control. It is the value of a drop down list in the user control. When I try to use it in an If statement on an aspx page it says that the variable is not declared. Is there a way to declare the variable on the aspx page or make it recognize that it is declared on the user control page?
I'm calling the code at the top of the aspx page
<%@ Register src="pType.ascx" tagname="pType" tagprefix="uc2" %>
I'm using the if statement
<%If pt.SelectedValue = "1" Then%>
\\do things
<%End If%>
In the control pt is defined by
<asp:DropDownList ID="pt" runat="server">
Thank you!
MetalAsp.Net
All-Star
112168 Points
18255 Posts
Moderator
Re: User control variable not declared
Feb 21, 2013 04:49 AM|LINK
You can declare a public property in the user control that encapsulates that value and read that value on the aspx page that way.
ramiramilu
All-Star
95493 Points
14106 Posts
Re: User control variable not declared
Feb 21, 2013 05:45 AM|LINK
example tutorial - http://stackoverflow.com/questions/2257829/access-child-user-controls-property-in-parent-user-control
thanks,
JumpStart
Pengzhen Son...
Star
8220 Points
846 Posts
Microsoft
Re: User control variable not declared
Feb 22, 2013 09:28 AM|LINK
Hi,
You can declare the variable as public in the user control's code and access it like this
<%= userControlID.variableName %>
Please refer here
http://www.devx.com/tips/Tip/27886
Feedback to us
Develop and promote your apps in Windows Store