Click here to Skip to main content
15,903,385 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I want to check a condition while click on button.
i call a script to the button for getting a message box.
like this
-----------
.aspx page
XML
<script type = "text/javascript">
        function Confirm() {
            var confirm_value = document.createElement("INPUT");
            confirm_value.type = "hidden";
            confirm_value.name = "confirm_value";
            if (confirm("Do you want to save data?")) {
                confirm_value.value = "Yes";
            } else {
                confirm_value.value = "No";
            }
            document.forms[0].appendChild(confirm_value);
        }
    </script>

XML
<asp:CheckBox ID="chkbox" runat="server" />
   <asp:Button ID="btnConfirm" runat="server" OnClick = "OnConfirm" Text = "Raise Confirm" OnClientClick = "Confirm()"/>


.cs File
C#
public void OnConfirm(object sender, EventArgs e)
    {
        string confirmValue = Request.Form["confirm_value"];
        if (confirmValue == "Yes")
        {
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);
        }
        else
        {
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
        }
    }
NOW I WANT TO CHECK THE CHECK BOX IS SELECT OR NOT DURING THE BUTTON CLICK
Posted
Updated 21-Mar-13 23:54pm
v2
Comments
pryashrma 23-Mar-13 3:13am    
do it in javascript

Hi Manju,
You can get the value of the checkbox control in your javascript function

JavaScript
function Confirm() {
// your code here
 var chk = document.getElementById("chkbox").checked;
 alert(chk );
}


Hope this helps you.

Regards,
Lok..
 
Share this answer
 
use Confirm function of javascript []

And no need to check in the
C#
public void OnConfirm(object sender, EventArgs e)

again for the Yes or NO clicked by user.
public void OnConfirm(object sender, EventArgs e)
will be called only if the user click Yes.
 
Share this answer
 

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