Confirmation message box in webapplication

后端 未结 8 1644
刺人心
刺人心 2020-12-19 19:16

Am using the below message box in asp.net web application. Now i want to convert this message box as a confirmation message box and do something when it is true else means r

8条回答
  •  無奈伤痛
    2020-12-19 19:36

    Try this

    Add this on your cs file to display a confirm instead of alert

    string confirm = 
    "if(confirm('Are you surely want to do this ??')) __doPostBack('', 'confirmed');";
    ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", confirm, true);
    

    Add this on same page to check when user is coming from that confirmation box

    protected void Page_Load(object sender, EventArgs e)
    {
        string parameter = Request["__EVENTARGUMENT"];
        if (string.Equals("confirmed", 
                            parameter, 
                            StringComparison.InvariantCultureIgnoreCase))
        {
            // Call your server side method here
        }
    }
    

    For this I used __doPostBack you can learn more about it from here. Hope it'll help you

提交回复
热议问题