Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hello All,

I want to called Confirm alert message from codebehind(C#) and get value of OK & cancel button(on confirm alert message button),
C#
if(userclick ==true)
{
do further ...
}
else
{
 ....
}

please suggest me ,how can i achieve this?
Posted
Updated 4-Sep-12 1:37am
v2

C#
Button1.Attributes.Add("onclick", "javascript:return " + "confirm('your messege ')");
 
Share this answer
 
v2
hi madhuri
you can call javascript From server side or code behind by
putting this code in your else part
XML
string msg1;
       msg1 = "<script language='javascript'>alert('Are You Sure You Want To Delete Madhuri s Data !');</script>";
       if (!ClientScript.IsStartupScriptRegistered("error"))
           {
               RegisterStartupScript("error", msg1);
           }
 
Share this answer
 
v2
Comments
madhuri@mumbai 4-Sep-12 6:24am    
thanks for your rply,
but i want to Confirm box,i.e. it will return true on click of OK button & false on Cancel...
Member 10315546 5-Nov-13 16:17pm    
.l.
Devang Vaja 4-Sep-12 6:25am    
this will give u alert code behind
This will not gove You Button value coz it is not possible..You can change your conditions...
Member 10315546 5-Nov-13 16:17pm    
.l. x 1000000000000000.l. x 1000000000000000.l. x 1000000000000000.l. x 1000000000000000.l. x 1000000000000000
madhuri@mumbai 4-Sep-12 6:31am    
how can u say that this is not possible..
XML
string msg1;
        msg1 = "<script language='javascript'>confirm('are You sure you want to delete Madhuri s data ...!');</script>";
        if (!ClientScript.IsStartupScriptRegistered("error"))
        {
            RegisterStartupScript("error", msg1);
        }

this will give you confirm....
No thnx No sorry...
 
Share this answer
 
v2
try Like this

place this Javascript on aspx page
function Confirm() {
   var confirm_value = document.createElement("INPUT");
   confirm_value.type = "hidden";
   confirm_value.name = "confirm_value";
   if (confirm("Do you Want to View DashBoard?")) {
   confirm_value.value = "Yes";
   } else {
   confirm_value.value = "No";
   }
   document.forms[0].appendChild(confirm_value);
   }

Place Button/ImageButton
<asp:imagebutton id="btnSwitch2" runat="server" xmlns:asp="#unknown">
                       ImageUrl="~/Images/dptch.jpg" OnClick="OnConfirm" 
                       OnClientClick="javascript:Confirm();" style="width: 20px" Width="20px" 
                       Height="21px" ImageAlign="AbsMiddle" Visible="False" />


</asp:imagebutton>

in code behind
 Protected Sub OnConfirm(ByVal sender As Object, ByVal e As EventArgs)
      Dim confirmValue As String = Request.Form("confirm_value")
        If confirmValue = "Yes" Then
---Do what you want when Yes
        Else
 ---Do what you want when No
        End If
    End Sub

is in vb.net but you can convert to C# here http://www.developerfusion.com/tools/convert/csharp-to-vb/[^]

IN c# here
protected void OnConfirm(object sender, EventArgs e)
{
	string confirmValue = Request.Form("confirm_value");

	if (confirmValue == "Yes") {
----Do what You want when Yes
	}
	 else {
----Do what You want when  No
	}
}
 
Share this answer
 
v3
Comments
Devang Vaja 4-Sep-12 6:47am    
Bhai she wants in c# .net..
Karwa_Vivek 4-Sep-12 6:51am    
Boss Cant you see the Link i posted to Convert it into C#...
Devang Vaja 4-Sep-12 6:53am    
ok boss u win i loose!!!!!
RAKESH CHAUBEY 4-Sep-12 7:10am    
lol

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900