tags:

views:

90

answers:

2

Hi all, After filling the form when i am clicking on submit button...nothing is happening i mean no events are performed. Pls help me... here is my code.. PatientProperty.cs

public class PatientProperty
{
    private string Pdisease;
    private string Pname;
    private string Pcategory;
    private string Paddr;
    private DateTime Dateofjoining;
    private int Page;

    public string PNAME
    {
        get
        {
            return Pname;
        }
        set
        {
            Pname = value;
        }
    }    
    public string PADDRESS
    {
        get
        {
            return Paddr;
        }
        set
        {
            Paddr = value;
        }
    }    
    public int PAGE
    {
        get
        {
            return Page;
        }
        set
        {
            Page = value;
        }
    }
    public string PDISEASE
    {
        get
        {
            return Pdisease;
        }
        set
        {
            Pdisease = value;
        }
    }
    public string PCATEGORY
    {
        get
        {
            return Pcategory;
        }
        set
        {
            Pcategory = value;
        }
    }
    public DateTime DATEOFJOINING
    {
        get
        {
            return Dateofjoining;
        }
        set
        {
            Dateofjoining = value;
        }
    }
}
PatientRegistration.cs
public class PatientRegistration
{
    string str = ConfigurationManager.ConnectionStrings["HealthCare"].ConnectionString.ToString();    
    public void InsertPatient(PatientProperty obj)
    {
        using (var con = new SqlConnection(str))
        {
            using (var com = new SqlCommand("PatientRegister", con))
            {
                com.CommandType = CommandType.StoredProcedure;               
                com.Parameters.AddWithValue("Pname", obj.PNAME);
                com.Parameters.AddWithValue("Paddr", obj.PADDRESS);
                com.Parameters.AddWithValue("Page", obj.PAGE);
                com.Parameters.AddWithValue("Pdisease", obj.PDISEASE);
                com.Parameters.AddWithValue("Pcategory", obj.PCATEGORY);               
                com.Parameters.AddWithValue("Dateofjoining", obj.DATEOFJOINING);                       con.Open();
                com.ExecuteNonQuery();
                con.Close();              
            }
        }
    }
}
PatientRegistrationBussiness.cs
public class PatientRegistrationBussiness
{
    public void AddPatient(PatientProperty obj)
    {
        PatientRegistration PR = new PatientRegistration();
        PR.InsertPatient(obj); 
    }   
}
protected void Button1_Click(object sender, System.EventArgs e)
{            
            string name = TextBox2.Text;
            string address = TextBox3.Text;
            string category = RadioButtonList1.Text;
            int age =Convert.ToInt32(TextBox4.Text);
            string disease = TextBox5.Text;
            DateTime date =Convert.ToDateTime(TextBox6.Text);           
            PatientRegistrationBussiness obj = new PatientRegistrationBussiness();           
            try
            {
                PatientProperty PP = new PatientProperty();  
                PP.PNAME = name;
                PP.PADDRESS = address;                
                PP.PAGE = age;
                PP.PDISEASE = disease;
                PP.PCATEGORY = category.ToString();
                PP.DATEOFJOINING = date;
                obj.AddPatient(PP);
                Response.Write("Patient details have been successfully added");
                TextBox2.Text = string.Empty;
                TextBox3.Text = string.Empty;
                TextBox4.Text = string.Empty;
                TextBox5.Text = string.Empty;
                TextBox6.Text = string.Empty;
                RadioButtonList1.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            finally
            {
                obj = null;
            }    
}
+1  A: 

Try putting a breakpoint in the Button1_Click method. In particular, I expect that an exception is being thrown and lost:

        catch (Exception ex)
        {
            ex.Message.ToString();
        }

does nothing! Either show the message to the user, or log it somewherre (perhaps Trace.WriteLine(ex)).

Also - don't set obj to null - there is no purpose.

Marc Gravell
I don't see the event registration here. do you? :(
Henrik P. Hessel
Hi... I have removed obj=null. and have put break point..control is not going to dataaccess layer and bussinessaccess layer.Once it reaching to catch block its coming out...and showing the unsubmitted form again.
+2  A: 

You have to hook up your events e.g. this.Load += new EventHandler(Page_Load); unless you set the AutoEventWireup="true".

Dave Anderson