Javascript confirmation message issue

I have a confirmation popup that I can show as below.

But I do not know if the user clicked ok or canceled.

                ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax", "<script language='javascript'>confirm('Do u wanna change?');</script>", false);

so what I want to do like this.

if (orignalId != newId)
                {
 ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax", "<script language='javascript'>confirm('Do u wanna change?');</script>", false);

If (user clicks Yes)
{
add some data to SQL
}
else
{
return;
}
}

How to find out what the user clicked?

I tried this

  • I put the code below in the folder1 \ jscrip.js file, but I don’t know what to name it, because I have the ajax update panel used on the page, so I can not use ClientScript.RegisterClientScriptInclude to link to it. as indicated in paragraph 6 by this link: http://www.dotnetcurry.com/ShowArticle.aspx?ID=274

Page.ClientScript.RegisterClientScriptInclude ("selective", ResolveUrl (@ "folder1 \ jscrip.js"));

function confirmation()
{
if(confirm("Are you sure?")==true)
return true;
else
return false;
}

Any suggestions??? thank

functionality:

" ", "if (orignalId!= newId)", , . , , ,

:

protected void Page_Load(object sender, EventArgs e)
        {
if (!IsPostBack)
            {
            }
 else if (Label.Text != "")
            {
                Global.logger.Debug("Postback Happ, Label = " + Label.Text);
                Button2_Click(sender, e);
            }
        }

 protected void Button2_Click(object sender, EventArgs e)
        { if (orignalCsId != 0 && newCsId != 0)
                {
                    if (orignalId != newId)
                    {
                        Global.logger.Debug("Pop Up crossed1");
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax", String.Format(CultureInfo.InvariantCulture, @"__doPostback('{0}', confirm('Your Data From iD1 will be populated in iD2?').toString());", Label.Text), true);
                    }
                    else if (Page.Request["__EVENTTARGET"] == Label.Text)
                    {
                        Global.logger.Debug("__EVENTARGUMENT1 = " + Page.Request["__EVENTARGUMENT"]);
                        bool userClickedOK = Boolean.Parse(Page.Request["__EVENTARGUMENT"]);
                        if (userClickedOK)
                        {
                            // Add some data to SQL.
                        }
                        else
                        {
                            return;
                        }
                        Label.Text = "";
                    }
                }
          }
+3
4

, , . __ doPostBack(), , confirm() :

if (originalId != newId) {
    ScriptManager.RegisterStartupScript(this, GetType(), "ajax",
        String.Format(CultureInfo.InvariantCulture, @"
            __doPostBack('{0}', confirm('Are you sure?').toString());
        ", yourUpdatePanel.ClientID), true);
} else if (Page.Request["__EVENTTARGET"] == yourUpdatePanel.ClientID) {
    bool userClickedOK = Boolean.Parse(Page.Request["__EVENTARGUMENT"]);
    if (userClickedOK) {
        // Add some data to SQL.
    } else {
        return;
    }
}

. , , script ( , true RegisterStartupScript(), <script> ).

__doPostBack(), confirm(). __doPostBack() : ClientID , ( ) . ASP.NET, , , .

, , UpdatePanel - , ASP.NET ( , UpdateMode, ). __doPostBack() ClientID UpdatePanel, , , confirm(), .

, , . , originalId newId , , , ( else if).

, __doPostBack(), __EVENTTARGET __EVENTARGUMENT. , , UpdatePanel, , , , __EVENTARGUMENT . Boolean.Parse(), , , , .

+3

"" true false, . @ . , . .

function confirmDelete()
{

    var x = confirm("Are you sure you want to Delete?");
    if (x)
    { 
        document.getElementById('Hidden1').value = "True";
    }
    else
    {
        document.getElementById('Hidden1').value = "False";
    }
}

if (orignalId != newId)
                {
 ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax", "<script language='javascript'>confirmDelete();</script>", false);

If (Hidden1.value=="True")
{
add some data to SQL
}
else
{
return;
}

}

+1

, , , , - , . javascript , ( , ..) , ​​ db, , , OnClientClick asp: button asp: linkbutton :

<asp:LinkButton Text="Delete" ID="DeleteProj" runat="server" CommandName="deleteproj" OnClientClick="return confirm('Are you sure?');" CommandArgument='<%# Eval("ProjectID") %>'/> 

By clicking the "No" button, you will send the user back to your page by clicking "yes", any C # code that you set for him will be launched. It worked for me.

0
source

ScriptManager.RegisterStartupScript often tends to block a popup. If you try the approach in the link below, you will have full control over each click of the mouse in the pop-up window.

http://02e34b5.netsolhost.com/youtube/Zpopup.aspx

This popup does not need ajax, javascript, jquery or css trick, but gives you full control.

0
source

Source: https://habr.com/ru/post/1791053/


All Articles