从 UserControl 页面,在父页面中调用 Page_Prerender [英] From UserControl page, Call Page_Prerender in Parent page
问题描述
我有一个 aspx 页面名称 MakeRedemption.aspx,其中有一个 UserControl (Search.ascx).
I have a aspx page name MakeRedemption.aspx, in which have a UserControl (Search.ascx).
MakeRedemption.aspx 中有 Page_Prerender().
There is Page_Prerender() in the MakeRedemption.aspx.
我想问一下,如何通过 Search.ascx 中的函数调用 MakeRedemption.aspx 中的 Page_Prerender().
I would like to ask, how can I call the Page_Prerender() from MakeRedemption.aspx, by a function in Search.ascx.
内容如下:
实际上,我的用户控制页面中的其中一个函数存在循环.
Actually there is a looping in one of the function in my User Control page.
Page_Prerender (MakeRedemption.aspx) 将在所有循环完成后触发.
The Page_Prerender (MakeRedemption.aspx) will trigger after all the loop finish.
我想要的是:每次在循环的每个项目结束之前,我都想触发 MakeRedemption.aspx 上的 Page_Prerender 来做某事.
类似的东西:
What I want is :
Everytime before end of each itme of the loop, I will like to trigger the Page_Prerender on the MakeRedemption.aspx to do something.
Something like :
for (int i = 0 ; i < 10 ; i ++)
{
//some code here
// I would like to trigger Page_Prerender here to do something before end of the loop.
} // the Page_Prerender (in MakeRedemption.aspx) trigger after all the loop finish.
意思是,这个 for 循环有 i = 10,因此,我想在 for 循环内触发 Page_Prerender 10 次.
Means that, this for loop has i = 10, thus, I would like to trigger the Page_Prerender 10 times inside the for loop.
我在 aspx 文件中的 PreRender 函数如下:
My PreRender function in the aspx file is as follow :
protected void Page_Prerender(object sender, EventArgs e)
{
//some code here
}
不确定这个 Page_Prerender() 是否被认为是自动生成的 OnPreRender().
Not sure this Page_Prerender() is consider as the auto generate OnPreRender() or not.
我想触发这个 Page_Prerender() 而不是 OnPreRender() .
I would like to trigger this Page_Prerender() instead of OnPreRender() .
对不起,如果我问了一个愚蠢的问题,我是编程和 C# 的新手.
Sorry if I am asking a stupid question, I am new in programming and c#.
请多多指教.
谢谢.
推荐答案
我终于找到方法了,oodng 如下:在 aspx.cs 页面中添加以下代码:
Finally i find the way to do it, the oodng is as follow : Add this following code in the aspx.cs page:
delegate void DelMethodWithoutParam();
protected void Page_Load(object sender, EventArgs e)
{
DelMethodWithoutParam delParam = new DelMethodWithoutParam(Page_prerender);
this.ucSearchGifts.PageMethodWithNoParamRef = delParam;
}
Page_prerender(){
//some code here...
}
并在用户控件 cs 页面中添加以下代码:
and add this following code in the user control cs page:
private System.Delegate _delNoParam;
public Delegate PageMethodWithNoParamRef
{
set { _delNoParam = value; }
}
protected void Button1_Click(object sender, EventArgs e)
{
_delNoParam.DynamicInvoke();
}
点击用户控制页面中的Button1,会触发aspx页面中的Page_prerender(),即父页面.
When click on the Button1 in user control page, the Page_prerender() in aspx page, which is parent page, will be trigger.
这篇关于从 UserControl 页面,在父页面中调用 Page_Prerender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!