【发布时间】:2010-06-03 20:24:43
【问题描述】:
我有一个将主要内容分为两个区域的母版页。母版页正文部分有两个 asp:ContentPlaceHolder 控件,ID 分别为 cphMain 和 cphSideBar。
其中一个对应的内容页面在 cphMain 中有一个控件,需要引用 cphSideBar 中的一个控件。具体来说,cphMain 中的 SqlDataSource 引用 cphSideBar 中的 TextBox 以用作选择命令中的参数。当内容页面加载时出现以下运行时错误:
Could not find control 'TextBox1' in ControlParameter 'date_con'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Could not find control
'TextBox1' in ControlParameter 'date_con'.
Source Error: An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Could not find control 'TextBox1' in ControlParameter 'date_con'.]
System.Web.UI.WebControls.ControlParameter.Evaluate(HttpContext context, Control control) +1753150
System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +47
System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +114
System.Web.UI.WebControls.SqlDataSource.LoadCompleteEventHandler(Object sender, EventArgs e) +43
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Page.OnLoadComplete(EventArgs e) +8698566
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +735
我有点知道问题出在哪里...... ASP.NET 不喜欢 SqlDataSource 和 TextBox 在内容页面中的不同 asp:Content 控件中的事实。
作为一种解决方法,我在 cphMain 中有另一个 TextBox,其 SqlDataSource 具有 Visible=False。然后在 Page_Load() 事件处理程序中,将 cphSideBar 中 TextBox 的内容复制到 cphMain 中不可见 TextBox 的内容中。
通过我想出的解决方法,我得到了我想要的结果,但这似乎是一个 hack。我想知道我是否缺少更好的解决方案。
请指教。
【问题讨论】:
标签: asp.net master-pages