提交按钮不起作用

时间:2009-07-15 09:30:08

标签: c# form-submit

当我点击提交按钮填写表单后...没有发生任何事情我的意思是没有执行任何事件。请帮助我......这是我的代码.. 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;
            }    
}

2 个答案:

答案 0 :(得分:2)

你必须联系你的活动,例如this.Load += new EventHandler(Page_Load);除非您设置AutoEventWireup="true"

答案 1 :(得分:1)

尝试在Button1_Click方法中添加断点。特别是,我希望抛出和丢失异常:

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

什么都不做!向用户显示消息,或者将消息记录下来(可能是Trace.WriteLine(ex))。

另外 - 不要将obj设置为null - 没有目的。