C# 将整型和字符串值从母版页传递到内容页
我在母版页中有一个广播列表,当我选择其中一个时,它们会触发一个事件 现在,此事件不由我的母版页控制,而是由我的内容页控制。 我的问题是,是否可以以某种方式将int/字符串从母版页方法传递到内容页方法 另外,在这种情况下,我想将inti传递给contentpage方法 这就是我如何使他们适应的方法 处理事件的母版页代码C# 将整型和字符串值从母版页传递到内容页,c#,asp.net,master-pages,content-pages,C#,Asp.net,Master Pages,Content Pages,我在母版页中有一个广播列表,当我选择其中一个时,它们会触发一个事件 现在,此事件不由我的母版页控制,而是由我的内容页控制。 我的问题是,是否可以以某种方式将int/字符串从母版页方法传递到内容页方法 另外,在这种情况下,我想将inti传递给contentpage方法 这就是我如何使他们适应的方法 处理事件的母版页代码 public event EventHandler Master_Save; ... public void RadioButtonList1_SelectedIndexCha
public event EventHandler Master_Save;
...
public void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
int i=RadioButtonList1.SelectedIndex;
if(Master_Save!=null)
{ Master_Save(this, EventArgs.Empty); }
}
和我的内容页代码来处理事件
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
(this.Page.Master as Pages_MasterPage).Master_Save += new EventHandler(ContentPage_Save);
}
private void ContentPage_Save(object sender, EventArgs e)
{
//Code that changes a query
}
当然可以,只需定义自定义事件args类并使用它参数化事件:
public class MasterSaveEventArgs : EventArgs
{
public int Index { get; private set; }
public MasterSaveEventArgs(int index)
{
this.Index = index;
}
}
然后使用它:
public event EventHandler<MasterSaveEventArgs> Master_Save;
...
{ Master_Save(this, new MasterSaveEventArgs(i)); }
...
(this.Page.Master as Pages_MasterPage).Master_Save += ContentPage_Save;
// notice the shortened syntax here
...
private void ContentPage_Save(object sender, MasterSaveEventArgs e)
谢谢你的回复。但是,在我的EventHandler行中,我的PreInt方法有一个错误。你能帮我弄清楚吗that@user3070259,编辑答案。对于将来的情况,指定您遇到的错误总是很有用的,否则您会让其他人猜测