1
protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
{           
    if (ddlLanguage.SelectedValue=="es-ES")
    {
        Page page = HttpContext.Current.CurrentHandler as Page;

        page.ClientScript.RegisterStartupScript(typeof(Page), "Script", "<script language='javascript'>alert('All content may not be in Spanish. Do you want to continue...');</script>");            
    }
}

All I want to do is display a simple alert box but all in vain...nothing pops-up. need some ayudar.

4
  • 1
    Are you sure that the page is actually doing a postback? Do you have AutoPostBack set to true on ddlLanguage? Commented Sep 13, 2012 at 15:32
  • Several problems in your code, but the most prominent is that you are asking for confirmation using alert. For this, you need to use confirm Commented Sep 13, 2012 at 15:41
  • ddlLanguage.Attributes.Add("OnSelectedIndexChanged", "return confirm(All content may not be in Spanish. Do you want to continue?');"); Commented Sep 13, 2012 at 15:44
  • @lcarus same result.. (nothing) :( Commented Sep 13, 2012 at 15:45

3 Answers 3

2

You can also achieve in this way

protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
{           
  if (ddlLanguage.SelectedValue=="es-ES")
   {         
      Response.Write("<script>alert('All content may not be in Spanish. Do you want to continue...');</script>");            
   }
}
Sign up to request clarification or add additional context in comments.

3 Comments

that seems like a easy fix, it works. But are there any good practice s for doing this..
currently when the alert box is displayed the background goes black. is it possible to keep my website in background and just display this alert box on top of it..
I am trying to use a confirm box instead of alert but its not working even if I cancel it still changes the content to spanish
2

You need to verify if the startup script is not registered already. Check out this post.

Also you can build your custom MessageBox in ASP.NET. Check out this one.

Comments

0

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "showalert","Alert Message", true);

This works for me without Postback try this

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.