Click here to Skip to main content
15,906,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
After filling all the datails in the registration form and click on submit button nothing is happening...only the password textbox get clear... also it is not showing any error... I don't know where is the problem in my code.

Here is .aspx code:

ASP.NET
<%@ Page Language="C#" MasterPageFile="~/MainMasterPage.master" AutoEventWireup="true"
    CodeFile="StudentRegistration.aspx.cs" Inherits="StudentRegistration" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentBody" runat="Server">
    <center>
        <form id="form1" runat="server">
        <table>
            <tr>
                <td colspan="2">
                    Registration Form
                </td>
            </tr>
            <tr>
                <td>
                    First Name
                </td>
                <td>
                    <asp:TextBox ID="txtFName" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvFName" runat="server" ControlToValidate="txtFName"
                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Last Name
                </td>
                <td>
                    <asp:TextBox ID="txtLName" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvLName" runat="server" ControlToValidate="txtLName"
                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Contact No
                </td>
                <td>
                    <asp:TextBox ID="txtContactNo" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvContactNo" runat="server" ControlToValidate="txtContactNo"
                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Email-Id
                </td>
                <td>
                    <asp:TextBox ID="txtEmail" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtContactNo"
                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Address
                </td>
                <td>
                    <asp:TextBox ID="txtAddress" runat="server" Width="150" TextMode="MultiLine"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvAddress" runat="server" ControlToValidate="txtAddress"
                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Date Of Birth
                </td>
                <td>
                    <asp:TextBox ID="txtDOB" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvDOB" runat="server" ControlToValidate="txtDOB"
                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    User Name
                </td>
                <td>
                    <asp:TextBox ID="txtUserName" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="efvUserName" runat="server" ControlToValidate="txtUserName"
                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Password
                </td>
                <td>
                    <asp:TextBox ID="txtPassword" runat="server" Width="150" TextMode="Password"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvpassword" runat="server" ControlToValidate="txtPassword"
                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Role
                </td>
                <td>
                <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem>Student</asp:ListItem>
                    <asp:ListItem>Teacher</asp:ListItem>
                </asp:RadioButtonList>
                
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Select role" ControlToValidate="RadioButtonList1"></asp:RequiredFieldValidator>
           </td>
                     </tr>
            <tr>
                <td>
                    Security Question
                </td>
                <td>
                    <asp:TextBox ID="txtSecQues" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvsecques" runat="server" ControlToValidate="txtSecQues"
                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Security Answer
                </td>
                <td>
                    <asp:TextBox ID="txtSecAns" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvSecAns" runat="server" ControlToValidate="txtSecAns"
                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
                </td>
            </tr>
        </table>
        <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
        </form>
    </center>
</asp:Content>


Code-behind

C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class StudentRegistration : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    static int i;
    static string strMsg;
    BALQuestions insobj = new BALQuestions();
    public void InsertStudentDetails()
    {

        DateTime DateConverted;
        bool IsValid = DateTime.TryParse(txtDOB.Text.Trim(), out DateConverted);
        if (IsValid == false)
        {
            return; //value in TextBox2 is not valid
        }

        insobj.FName = txtFName.Text;
        insobj.LName = txtLName.Text;
        insobj.ContactNo = txtContactNo.Text;
        insobj.Email = txtEmail.Text;
        insobj.Address = txtAddress.Text;
        insobj.DOB = DateConverted.ToString("dd-MM-yyyy");
        insobj.UserName = txtUserName.Text;
        insobj.Password = txtPassword.Text;
        insobj.role = RadioButtonList1.SelectedValue;
        insobj.SecQues = txtSecQues.Text;
        insobj.SecAns = txtSecAns.Text;
        i = insobj.InsertStudent(out strMsg);
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            InsertStudentDetails();
            if (i &gt; 1)
            {
                ClearData();
                lblMsg.Text = strMsg;
            }
            else
                lblMsg.Text = strMsg;
            
        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
        }
    }
    public void ClearData()
    {
        txtFName.Text= txtLName.Text = txtContactNo.Text = txtAddress.Text= txtDOB.Text="";
        txtUserName.Text = txtPassword.Text = txtSecQues.Text = txtSecAns.Text = "";
    }
}
Posted
Updated 27-Mar-16 1:53am
v2
Comments
Member 11712753 27-Mar-16 6:26am    
I wonder if you know how to use a debugger.
Member 12170781 27-Mar-16 6:52am    
I am using visual studio...please help me out

1 solution

Start with the debugger.
Put a breakpoint on the first line of the InsertStudentDetails method, and run your code in the debugger. When it tries to execute the method, it will stop and let you take control. Step through each line one by one, looking closely at exactly what is happening.
At a guess, your DateTime.TryParse is failing - but you need to look closely at your data to find out why.
If it isn't, then continue stepping until something happens that you don't expect, or some data looks wrong.
We can't do any of this for you - we don't have access to your data, and couldn't run your code under the same conditions if we did! So give it a try and see what you can find out.
 
Share this answer
 
Comments
Member 12170781 27-Mar-16 10:27am    
yes, U r right.I used breakpoint and find out that after clicking on submit button it is first executing this line :- "bool IsValid = DateTime.TryParse(txtDOB.Text.Trim(), out DateConverted);" . At that point the value of 'IsValid' is false but it is suppose to be true because I have entered a value in textbox of DOB i.e 01/01/2001...Now how can I sort out this?
OriginalGriff 27-Mar-16 11:16am    
Before you execute the line, it will be false, because that is the default value of a bool.
It's immediately after you execute it that you are interested in!
If it's still false, then that means that the computer you are executing the code on isn't set to evaluate "01/01/2001" as a date - it may be set to a different culture. And bear in mind that the computer running the client browser may not be in the same country as the server running the C# code: so converting dates by just using TryParse can get iffy.
Consider using a Calendar control instead which returns a DateTime value directly, and the user can't enter an invalid value at all!

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