0
votes

I am new in development, I want to show the alert message on button click after that I want to redirect the on another page. my button code is like below:

 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
    Response.Write("<script type='text/javascript'> alert('Please wait for approval!');</script>");
                Response.Redirect("~/profile/scrapbook.aspx?uid=" + Request.QueryString["uid"], false);
}

in this case alert is not working, If I remove the Response.Redirect then it will works properly.

Please suggest me how to call he alert message after that redirect on another page.

3
Friend request? Is it you, Zuckerberg?Radu

3 Answers

1
votes

You are mixing server side and client side code.

The Response.Redirect("~/profile/scrapbook.aspx?uid= is server side and the Alert won't wait the action of the user to execute it...

What you will need is to do you redirect in Javascript or to use something else than an Alert for the message.

Solution 1

You display a Alert message in Javascript (client side) when the user press okay you do a redirect in Javascript.

Solution 2

You display a message in the HTML with a button in ASP with an event that will do a call to the server and redirect your user to the page you desire.

1
votes

Add your script like this:

 const string scriptString = "<script type='text/javascript'> alert('Your friend request sent to the user! Please wait for approval!');</script>";
                ClientScriptManager script = Page.ClientScript;
                script.RegisterClientScriptBlock(GetType(), "randomName", scriptString);
0
votes

Do not use Response.Write to render your JavaScript. Use RegisterClientScriptBlock or RegisterStartupScript instead.

Your example should be using RegisterStartupScript, since it's rendering executing script, and not function declarations.