alhakimyyes says:
string
url =
"~/main.aspx"
;
Change above code with below.
string url = "main.aspx";
Check the below sample.
HTML
<asp:Button Text="Redirect" OnClick="btnRedirect_Click" runat="server" />
Code
C#
protected void btnRedirect_Click(object sender, EventArgs e)
{
string message = "You will now be redirected to Main Page.";
string url = "main.aspx";
string script = "window.onload = function(){ alert('";
script += message;
script += "');";
script += "window.location = '";
script += url;
script += "'; }";
ClientScript.RegisterStartupScript(this.GetType(), "Redirect", script, true);
}
VB.Net
Protected Sub btnRedirect_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim message As String = "You will now be redirected to Main Page."
Dim url As String = "main.aspx"
Dim script As String = "window.onload = function(){ alert('"
script += message
script += "');"
script += "window.location = '"
script += url
script += "'; }"
ClientScript.RegisterStartupScript(Me.GetType(), "Redirect", script, True)
End Sub