Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript SQL
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
<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>
<asp:CheckBox ID="chkbox" runat="server" />
   <asp:Button ID="btnConfirm" runat="server" OnClick = "OnConfirm" Text = "Raise Confirm" OnClientClick = "Confirm()"/>
 
.cs File
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 22-Mar-13 0:23am
Edited 22-Mar-13 0:54am
Maciej Los151.7K
v2
Comments
pryashrma at 23-Mar-13 3:13am
   
do it in javascript
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi Manju,
You can get the value of the checkbox control in your javascript function
 
function Confirm() {
// your code here
 var chk = document.getElementById("chkbox").checked;
 alert(chk );
}
 
Hope this helps you.
 
Regards,
Lok..
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

use Confirm function of javascript []
 
And no need to check in the
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 23 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100