简体   繁体   中英

passing an argument from an aspx page to a UserControl

I am having a problem passing a variable to a user control. When I pass a hard-coded value, my control works fine. However passing a variable is not working.

My ASPX code:

<% System.Console.Out.WriteLine("Operate Flag is set to: " + operateFlag); %>
<uc:menu ID="navigationMenu" runat="server" operate="<%# operateFlag %>" />

From debug output, it is clear that operateFlag is set to 'true'.

My control codebehind only has synthesized methods as below:

public partial class MenuControl : System.Web.UI.UserControl
{
    public bool operate { get; set; }
}

I also print out the received value from inside the control:

<% System.Console.Out.WriteLine("Operate Flag is received as: \'" + operate + "\'"); %>

Here, operate is received by the control as False.

I figured out a way to get my page working. Still do not understand what was wrong with the original "form." Now, as before from OnLoad(), I set the property of the control instead of passing a variable as:

navigationMenu.operate = false; 

It solves my need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM