Event binding and dynamic UC loading in PageManager pattern.

Rate It (2)

Last post 01-08-2007 2:28 AM by mfarshadmehr. 2 replies.

Sort Posts:

  • Event binding and dynamic UC loading in PageManager pattern.

    12-25-2006, 3:34 AM
    • Loading...
    • mfarshadmehr
    • Joined on 09-09-2006, 10:45 AM
    • Neyshabour , Yazd , IR
    • Posts 149

    I use fallowing pattern to load UserControl (i say page) according to user action:

    comments:

    ViewState["OldQuery"]  is used for saving previous loaded UC (page) name. 

    and queryMedium is a HiddenField that i set its value in client by script for set page of new page (to load).

     

    protected override void LoadViewState(object savedState)

    {

    base.LoadViewState(savedState);

    //Recreate page of previous request

    if (ViewState["OldQuery"] != null && ViewState["OldQuery"] != "")

    pagePlaceHolder.Controls.Add(BuildPage(ViewState[

    "OldQuery"].ToString()));

    }

    protected override void OnPreRender(EventArgs e)

    {

    //removing old page and refresing viewsatate in page navigation

    if (queryMedium.Value != "")

    {

    if (ViewState["OldQuery"] != null && ViewState["OldQuery"] != "")

    pagePlaceHolder.Controls.RemoveAt(0);

    ViewState[

    "OldQuery"] = queryMedium.Value;

    queryMedium.Value =

    "";

    }

    }

    protected void Page_Load(object sender, EventArgs e)

    {

    //Set first page to navigate

    if (ViewState["OldQuery"] == null && queryMedium.Value == "")

    queryMedium.Value =

    "_PageName=" + defualtPage + ";";

    //Load new page

    if (queryMedium.Value != "")

    pagePlaceHolder.Controls.Add(BuildPage(queryMedium.Value));

    }

    Problem:

    previuos loaded UC (page) event handler fire after new page load (in event that cause to loading new page) so i can't use of that method result in new page load.

    i know that this because of that even occur after page load and i load new page in load.

    to solve this new problem i can move load new page section to OnPreRender but this new solution cause new third problem , event handler will not fire.

    another solutions are using callback function to doing action before loading new page or refreshing page after action competion to load new page.

    Be the best
  • Re: Event binding and dynamic UC loading in PageManager pattern.

    12-26-2006, 3:34 AM
    • Loading...
    • mfarshadmehr
    • Joined on 09-09-2006, 10:45 AM
    • Neyshabour , Yazd , IR
    • Posts 149

    any one have any idea?

    i'm need your help. do you know more about events fire in ASP.NET?

    Be the best
  • Re: Event binding and dynamic UC loading in PageManager pattern.

    01-08-2007, 2:28 AM
    • Loading...
    • mfarshadmehr
    • Joined on 09-09-2006, 10:45 AM
    • Neyshabour , Yazd , IR
    • Posts 149

    I have solved my problem and document my approach completely here :

    http://forums.asp.net/thread/1516741.aspx

    for any one who is interested.

    Be the best
Page 1 of 1 (3 items)
Microsoft Communities
Page view counter