问题
I have a aspx page name MakeRedemption.aspx, in which have a UserControl (Search.ascx).
There is Page_Prerender() in the MakeRedemption.aspx.
I would like to ask, how can I call the Page_Prerender() from MakeRedemption.aspx, by a function in Search.ascx.
It is something as follow :
Actually there is a looping in one of the function in my User Control page.
The Page_Prerender (MakeRedemption.aspx) will trigger after all the loop finish.
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.
Means that, this for loop has i = 10, thus, I would like to trigger the Page_Prerender 10 times inside the for loop.
My PreRender function in the aspx file is as follow :
protected void Page_Prerender(object sender, EventArgs e)
{
//some code here
}
Not sure this Page_Prerender() is consider as the auto generate OnPreRender() or not.
I would like to trigger this Page_Prerender() instead of OnPreRender() .
Sorry if I am asking a stupid question, I am new in programming and c#.
Kindly advise.
Thanks.
回答1:
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...
}
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();
}
When click on the Button1 in user control page, the Page_prerender() in aspx page, which is parent page, will be trigger.
来源:https://stackoverflow.com/questions/17139714/from-usercontrol-page-call-page-prerender-in-parent-page