[英]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: 我的ASPX代码:
<% 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'. 从调试输出中可以明显看出,operateFlag设置为“ 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. 在此,操作被控件接收为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:
现在,像以前从OnLoad()一样,我设置控件的属性,而不是将变量传递为:
navigationMenu.operate = false;
It solves my need. 它解决了我的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.