Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
I want to redirect the page on other form when click on ok of confirm and when click on cancel then cancel how i do this.. i use below code but this is not redirect to another page. i want to use the server side confirm not client side

C#
protected void Page_Load(object sender, EventArgs e)
{
    string message1 = "Do you want to Submit?";
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append("return confirm('");
    sb.Append(message1);
    sb.Append("');");
    ClientScript.RegisterOnSubmitStatement(this.GetType(), "alert", sb.ToString());

}
On button click i call

protected void btnMsg_Click(object sender, EventArgs e)
        {





            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("<script type = 'text/javascript'>");
            sb.Append("window.onload=function(){");
            sb.Append("Response.Redirect('WebForm2.aspx'){");
            sb.Append("</script>");
            ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());

        }
    }
}

C#



What I have tried:

C#
I want to redirect on webform 2 on confirm ok button click and on cancel i move to another..but this is not done plz recmond how i redirect this
Posted
Updated 14-Nov-16 6:39am

Quote:
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("Response.Redirect('WebForm2.aspx'){");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());

Apart from the obvious syntax error, you're also trying to invoke a server-side method (Response.Redirect) from client-side code.

Replace the content of your event handler with:
C#
protected void btnMsg_Click(object sender, EventArgs e)
{
    Response.Redirect("WebForm2.aspx");
}



Quote:
i want to use the server side confirm not client side

There is no "server-side confirm". Code running on the server cannot display any UI to the client, except by returning content in the response. The only way to display a message to the user is via client-side code.
 
Share this answer
 
Check following article-
Server Side (Code Behind) Yes No Confirmation Message Box in ASP.Net[^]

Hope, it helps :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900