如何在ASP.NET C#中将aspx页面的下拉值传递给我的usercontrol? [英] How can a pass a dropdown value from aspx page to my usercontrol in ASP.NET C# ?
本文介绍了如何在ASP.NET C#中将aspx页面的下拉值传递给我的usercontrol?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
任何人都可以给我完整的代码,将下拉值(在我的.aspx页面中)传递给我的usercontrol页面。 />
请考虑我是初学者。
提前致谢
我尝试了什么:
如何将aspx页面的下拉值传递给我的usercontrol in asp.net C#?
Hi All,
Can anyone give me the full code to pass a dropdown value(which is in my .aspx page) to my usercontrol page.
Please consider that i'm a beginner.
Thanks in advance
What I have tried:
How can a pass a dropdown value from aspx page to my usercontrol in asp.net C# ?
推荐答案
您应该通过在usercontrol上创建其他控件可以使用的属性来传递数据。
用户控制
You should pass data by creating properties on your usercontrol that other controls can use.
User control
<p>
Data: <%=this.MyValue %>
</p>
用户控制代码背后
User control code behind
public partial class MyControl : System.Web.UI.UserControl
{
public string MyValue { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
}
}
带有下拉列表的aspx页面
aspx page with dropdown
<uc1:MyControl runat="server" ID="MyControl" />
<asp:DropDownList ID="MyDropDown" runat="server">
<asp:ListItem Text="One" Value="1" />
<asp:ListItem Text="Two" Value="2" />
<asp:ListItem Text="Three" Value="3" />
</asp:DropDownList>
<asp:Button ID="ButtonSubmit" runat="server" OnClick="ButtonSubmit_Click" Text="Submit" />
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
MyControl.MyValue = MyDropDown.SelectedValue;
}
这篇关于如何在ASP.NET C#中将aspx页面的下拉值传递给我的usercontrol?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文