ASP.Net 用户控制事件冒泡 (C#)
非常感谢。我已经尽职调查并研究了两天,但似乎无法理解在线教程所描述的内容。
情况:首席程序员辞职。公司老板知道我兼职做了一些(新手)VB.NET,并要求我在他的 Intranet 应用程序(用 C# 编写)上的 2 个自定义用户控件之间连接功能。回答专业人士的小考虑 - 我很流利在 Visual Studio 中...但仍在学习 C#)。
以下是控件的简化描述,但希望足以让我们朝着正确的方向前进:
UserControl_1 包含多个链接按钮,单击这些链接按钮时,应更改 UserControl_2 中的 ObjectDataSource 使用的 SelectParameter 的值:
<asp:LinkButton ID="OpenBtn1" runat="server" Text="Show Open Requests" />
<asp:LinkButton ID="ClosedBtn1" runat="server" Text="Show Closed Requests" />
UserControl_2 (带有 DataSource 的 GridView):
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetDataBy_Status"
TypeName="adhoc_TblAdptrs.adhoc_TblAdptr">
<SelectParameters>
<asp:Parameter DefaultValue="All" Name="status" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:GridView1 ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" />
我想要将新的默认值传递给 UserControl_2 中 ObjectDataSource 的 SelectParameter。期待专业人士的个性化解释!非常感谢您的帮助!
Many thanks in advance. I've done my due diligence and researched for 2 days, but can't seem to wrap my mind around what online tutorials describe.
The situation: Lead Programmer ups and quits. Owner of firm knows I've done some (novice) VB.NET on the side and asks me to wire up functionality between 2 custom user controls on his intranet app (written in C#. Small consideration for answering pros -- I'm fluent in Visual Studio...but still learning C#).
Here's a simplified description of controls, but hopefully enough to get us going in the right direction:
UserControl_1 contains multiple linkbuttons that, when clicked, should change the value of the SelectParameter being used by an ObjectDataSource in UserControl_2:
<asp:LinkButton ID="OpenBtn1" runat="server" Text="Show Open Requests" />
<asp:LinkButton ID="ClosedBtn1" runat="server" Text="Show Closed Requests" />
UserControl_2 (GridView with DataSource):
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetDataBy_Status"
TypeName="adhoc_TblAdptrs.adhoc_TblAdptr">
<SelectParameters>
<asp:Parameter DefaultValue="All" Name="status" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:GridView1 ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" />
What I'd like to do pass a new default value to the SelectParameter of the the ObjectDataSource in UserControl_2. I'm looking forward to a personalized explanation from the pros! Your help is greatly, greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将在 UserControl2 中公开一个属性,该属性将依次设置参数值
此外,在页面中创建将在控件中设置属性的公共方法
从这里,在链接按钮单击事件中,您可以使用设置公共属性页面的方法:
此方法将完成工作,但它将控件与链接按钮耦合到此特定页面。
如果您想删除耦合,那么您可以实现带有方法的接口
然后在您的页面中您将实现它并检查控制页面的代码
I would expose a property in UserControl2 that will, in turn, set the parameter value
Also, in the page create public method that will set the property in the control
From here, in the linkbutton click event, you can just set the public property using the page's method:
This method will get the job done but it will couple the control with the linkbuttons to this specific page.
If you want to remove the coupling then you could implement an Interface with the method
Then in your page you would implement it and do a check in the code for the control page