简体   繁体   中英

alert box from asp.net 3.5 Code-Behind

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.

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 .

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>");            
   }
}

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

This works for me without Postback try this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM