protected void btn_r_submit_Click(object sender, EventArgs e) { con.Open(); string strid = "select count(*) from tbl_user_register"; SqlCommand cmdid = new SqlCommand(strid, con); int count = Convert.ToInt16(cmdid.ExecuteScalar()) + 1; string struserid = count.ToString(); string strquery = "insert into tbl_user_register values('"+struserid+"','" + txt_fname.Text + "','" + txt_dob.Text + "','" + txt_r_loginid.Text + "','" + txt_r_pwd.Text + "','" + txt_r_confirmpwd + "','" + txt_r_email.Text + "','" + txt_r_mobile.Text + "')"; SqlCommand cmdregister = new SqlCommand(strquery, con); if (cmdregister.ExecuteNonQuery()>0) { Response.Write("<Script>alert('Successfully Registered in GVK Academy..')</Script>"); con.Close(); } else { try { con.Open(); } catch (Exception ex) { Response.Write(ex.Message); //return false; con.Close(); } }
<div id="div_signup"> <div id="div_sigbg"> <table class="auto-style1"> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2" style="background-color: #006699; color: #FFFFFF; text-align: center; font-weight: bold; height:30px; font-size: 25px; font-family: 'Courier New', Courier, monospace;">Student Registration</td> </tr> <tr> <td class="td_regist">Full Name :</td> <td class="auto-style4"> <asp:TextBox ID="txt_fname" CssClass="txt_register" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" SetFocusOnError="true" ControlToValidate="txt_fname" ValidationGroup="register" runat="server" ErrorMessage="*" ForeColor="#ff0000" Font-Bold="true"></asp:RequiredFieldValidator> </td> </tr> <tr> <td class="td_regist">Date Of Birth :</td> <td> <asp:TextBox ID="txt_dob" CssClass="txt_register" TextMode="Date" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" SetFocusOnError="true" ControlToValidate="txt_dob" ValidationGroup="register" runat="server" ErrorMessage="*" ForeColor="#ff0000" Font-Bold="true"></asp:RequiredFieldValidator> </td> </tr> <tr> <td class="td_regist">Login ID :</td> <td> <asp:TextBox ID="txt_r_loginid" runat="server" CssClass="txt_register" ></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" SetFocusOnError="true" ControlToValidate="txt_r_loginid" ValidationGroup="register" runat="server" ErrorMessage="*" ForeColor="#ff0000" Font-Bold="true"></asp:RequiredFieldValidator> </td> </tr> <tr> <td class="td_regist">Password :</td> <td> <asp:TextBox ID="txt_r_pwd" runat="server" TextMode="Password" CssClass="txt_register"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator4" SetFocusOnError="true" ControlToValidate="txt_r_pwd" ValidationGroup="register" runat="server" ErrorMessage="*" ForeColor="#ff0000" Font-Bold="true"></asp:RequiredFieldValidator> </td> </tr> <tr> <td class="td_regist">Confirm Passsword :</td> <td> <asp:TextBox ID="txt_r_confirmpwd" runat="server" TextMode="Password" CssClass="txt_register"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator9" SetFocusOnError="true" ControlToValidate="txt_r_confirmpwd" ValidationGroup="register" runat="server" ErrorMessage="*" ForeColor="#ff0000" Font-Bold="true"></asp:RequiredFieldValidator> <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txt_r_pwd" ControlToValidate="txt_r_confirmpwd" ForeColor="#ff0000" ErrorMessage="Password not matched"></asp:CompareValidator> </td> </tr> <tr> <td class="td_regist" >E-Mail Id :</td> <td> <asp:TextBox ID="txt_r_email" runat="server" CssClass="txt_register"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator5" SetFocusOnError="true" ControlToValidate="txt_r_email" ValidationGroup="register" runat="server" ErrorMessage="*" ForeColor="#ff0000" Font-Bold="true"></asp:RequiredFieldValidator> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" SetFocusOnError="true" runat="server" ForeColor="#ff0000" ControlToValidate="txt_r_email" ErrorMessage="Invaild email ID" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator> </td> </tr> <tr> <td class="td_regist">Mobile No :</td> <td> <asp:TextBox ID="txt_r_mobile" runat="server" CssClass="txt_register"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator6" SetFocusOnError="true" ControlToValidate="txt_r_mobile" ValidationGroup="register" runat="server" ErrorMessage="*" ForeColor="#ff0000" Font-Bold="true"></asp:RequiredFieldValidator> <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" SetFocusOnError="true" ControlToValidate="txt_r_mobile" ErrorMessage="Invalid Mobi no" ForeColor="Red" ValidationExpression="[789][0-9]{9}" ValidationGroup="register"></asp:RegularExpressionValidator> </td> </tr> <tr> <td> </td> <td> <asp:Label ID="lbl_registermessage" Visible="false" runat="server" ForeColor="#006600" Text="Successfully Registration Complete..."></asp:Label> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <asp:Button ID="btn_r_submit" CssClass="btn_register" runat="server" ValidationGroup="register" Text="Submit" OnClick="btn_r_submit_Click" ValidateRequestMode="Enabled" /> <asp:Button ID="btn_r_clear" CssClass="btn_register" runat="server" ValidationGroup="register" Text="Clear" OnClick="btn_r_clear_Click" /> </td> </tr> <tr> <td colspan="2" style="text-align:center"> </td> </tr> </table> </div> </div>