2014年7月13日 星期日

[RESOLVED] Usercontrol should not be postback


I have multiple pages with single user control.


I want that user control shold bring the values from database only first time for a page then for all pages it will persist the same values.


While navigating between page usercontrol should not be postback.



Did you try storing values in a session and assigne it to the controls in the other page? Give the data source in Not IsPostBack of the first page and save it in the session.



Hope this works



Hi,


For this situation, if multiple pages are using the user control, and you want to retrieve the datas from database only the first time, you could add the following codes within each of the pages' page_load event:


Session["FirstFalg"] = "true";
if (!IsPostBack && Session["FirstFalg"].ToString()=="true")
{
//retrieve datas from database, and assign to the datatable, then bind the datatable to the usercontrol
Session["TableData"] = dt;
Session["FirstFalg"] = "false";
}
else
{
//bind the datatable to the Session["TableData"]
}

Regards


沒有留言:

張貼留言