1

whenever the checkbox in dialog box is checked and after clicking the button it doesn't save the data to database its only save 'N' but is checkbox is checked then also it saves 'N' how to solve this problem. i want save 'Y' to database if checkbox is checked.

HTML:-this is the html section in which checkbox is declared

<form id="form1" runat="server">
    <div id="dialog">
    <label>First</label>
      <asp:CheckBox ID="CheckBox1" runat="server" />
      <label>Second</label>
      <asp:CheckBox ID="CheckBox2" runat="server" />
      <label>Third</label>
      <asp:CheckBox ID="CheckBox3" runat="server" />
     
    </div>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button2_Click" />
     
    </form>
    

Jquery:-here is the jquery script.dialogbox with checkbox

    <script type="text/javascript">
                $(document).ready(function () {
                    $("#dialog").dialog({
                        buttons: {
                            Ok: function () {
                                $("[id*=Button1]").click();
                            },
                            Close: function () {
                                $(this).dialog('close');
                            }
                        }
                    });
                    });
            </script>
    

Code Behind:- c# code behind file inserting data in database using ado and sql

    protected void Button2_Click(object sender, EventArgs e)
            {
        
                ClientScript.RegisterStartupScript(Page.GetType(), "key", "alert('Button Clicked')", true);
        
        
                string First = CheckBox1.Checked ? "Y" : "N";
                string Second = CheckBox2.Checked ? "Y" : "N";
                string Third = CheckBox3.Checked ? "Y" : "N";
        
                string cs = ConfigurationManager.ConnectionStrings["DUM01ConnectionString"].ConnectionString;
                using (SqlConnection scon = new SqlConnection(cs))
                {
                    using (SqlCommand cmd = new SqlCommand("insert into Checkbox (First,Second,Third) values(@First,@Second,@Third)"))
                    {
                        cmd.Connection = scon;
                        cmd.Parameters.AddWithValue("@First", First);
                        cmd.Parameters.AddWithValue("@Second", Second);
                        cmd.Parameters.AddWithValue("@Third", Third);
                        scon.Open();
                        cmd.ExecuteNonQuery();
                        scon.Close();
                    }
                }
            }
        

It saves only 'N' to the database if the checkbox is checked then also it saves 'N' to the database. How to solve this?

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • debug the code step by step and check what _value_ are you getting while you check the checkbox – Nad Jul 19 '16 at 12:14

1 Answers1

0

I debugged your code on my side, but didn't find any issue in the code. I was getting the expected value as Y whenever I checked the checkbox.

It seems the issue might be coming from somewhere else.

See the attached screenshot of my debugging.

CHK1

In the above screenshot, I checked the first checkbox and I got it's value as Y in the debugging part.

CHK2

Suggestion:

Try taking your code to a new fresh page and implement this part of your functionality. You will get an idea, that the issue is coming from somewhere else.

Hope this helps, Let me know if you face any other issues related to this.

UPDATE

Since you are using dialog box, have a look at the below link for your reference. It might help you

Dialogbox

Community
  • 1
  • 1
Nad
  • 4,605
  • 11
  • 71
  • 160