15
Reply

How to display Alert in JavaScript and ASP.NET

    we can display alert box from asp.net code-behind that is

    1. ScriptManager.RegisterStartupScript(this,GetType(),"alertmsg","alert('hahahahah');",true);





     #region :: Alert Messege ::
        public void showalert(string msg)
        {
            string script = "";
            if (!Page.IsStartupScriptRegistered("ClientScript"))
            {
                Page.RegisterStartupScript("ClientScript", script);
            }
        }
        #endregion

    below mention script how to write on button click with server side confirmation in asp.net

    Response.Write("")

    ///

    /// showAlert/// public string showAlert(string msg){string message = msg;System.Text.StringBuilder sb = new System.Text.StringBuilder();sb.Append("");return sb.ToString();} and then call above function likeClientScript.RegisterClientScriptBlock(this.GetType(), "alert",showAlert("Student already admitted to this batch."));

    page.registerstartupscript("sss","alert('student details not avlible')");

    Page.RegisterStartupScript("ddd", "alert('student details not avalible')");

    Page.RegisterStartupScript("ddd", "alert('student details not avalible')");

    Response.Write("alert('Duplicate files not allowed');");

    Response.Write("javascript:alert('Your message');");

    alert("message");

     IN order to Show MessageBox you can add the MessageBox Class in your page and use MessageBox.Show("Your Message");


    Link for MessageBox Class



    You need to drag script manager and then type the follwing code wherever u required

    ClientScript.RegisterClientScriptBlock(typeof(Page), "test", "");

    Response.Write("alert('Hello');");

    Write this line of code to diplay the alert message. Response.Write("alert('Hello Puru!!!')");