Skip to main content Skip to footer

Redirecting to a Page during Partial Postback in Wijmo

Many times we require to redirect the current page to a new page after completion of some I/O operations or when an event is raised. However, in such cases redirection to a new page is not possible due to occurrence of Page Callback. Page CallBack process performs only partial Postback whereas redirecting to a new page using Response.Redirect() or Server.Transfer() method requires a Full PostBack of the page. This blog implementation provides a solution to Redirect Page after the completion of Page Callback operation. Here I am taking an example when Page Callback occurs with Wijmo C1Editor control. Lets say, you want to write some text in the C1Editor and show the contents on a new page after saving. When user clicks the Save button on the Editor Ribbon, its OnTextSaved event is raised. This results in a Page CallBack (partial Postback).

protected void C1Editor1_TextSaved(object sender, EventArgs e)  
{  
    //Text saved in Session variable  
    Session["EditorText"] = C1Editor1.Text;  
    //This statement will cause the exception   
    Response.Redirect("~/TargetPage.aspx");  
}

If we use redirection in this event, an exception "Response.Redirect cannot be called in a Page callback" is raised. That is, Response.Redirect() cannot be called in TextSaved event. To resolve this, we need to handle the callbackComplete Client side event which gets executed after the OnTextChanged server side event. So after Page Callback is complete, location of the page can be changed to redirect to a new page. This can be done as follows:

<script type="text/javascript">  
$(document).ready(function () {  
     $.c1.c1editor.prototype._callbackComplete = function (response, context) {  
     if (context === "textSaved") {  
        //Do something here.  
        document.location.href = "TargetPage.aspx";  
     }  
     if (response === "") {  
        return;  
     }  
  }  
});  
</script>  

Then the text saved in Session variable can be retrieved on the TargetPage in its Form_Load event as follows:

protected void Page_Load(object sender, EventArgs e)  
{  
   string EditorText = Convert.ToString(Session["EditorText"]);  
   Label1.Text = EditorText;  
}

Please download the attached sample for complete implementation. Download Sample

MESCIUS inc.

comments powered by Disqus