Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
   {

      optxt.Text = dt;
   }


I am trying to compile this hospital management software and i stuck at following error. I google a lot but the solution does not work for me. Any help Will BE appreciated.


error at outpatient.aspx.cs and code is

C#
public partial class doctorsignup: System.Web.UI.Page
{
    //SqlConnection cn = new SqlConnection("server=IPOG-A95E1056D3;user id=sa;password=sqlserver;database=Hospitalmanagement");
    string dt = DateTime.Now.ToShortDateString();
    protected void Page_Load(object sender, EventArgs e)
    {

       optxt.Text = dt;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        cn.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "sp_hospital_outpatient";
        cmd.Connection = cn;

        SqlParameter p = new SqlParameter("@patientname",SqlDbType.VarChar,20);
        p.Value = pntxt.Text;
        cmd.Parameters.Add(p);

        SqlParameter p1 = new SqlParameter("@gender", SqlDbType.VarChar, 20);
        p1.Value = gddl.Text;
        cmd.Parameters.Add(p1);

        SqlParameter p2 = new SqlParameter("@age", SqlDbType.Int);
        p2.Value = agetxt.Text;
        cmd.Parameters.Add(p2);

        SqlParameter p3 = new SqlParameter("@address", SqlDbType.VarChar, 20);
        p3.Value = addtxt.Text;
        cmd.Parameters.Add(p3);

        SqlParameter p4 = new SqlParameter("@assigndoctor", SqlDbType.VarChar, 20);
        p4.Value = doctorddl.Text;
        cmd.Parameters.Add(p4);

        SqlParameter p5 = new SqlParameter("@phoneres", SqlDbType.BigInt);
        p5.Value = restxt.Text;
        cmd.Parameters.Add(p5);

        SqlParameter p6 = new SqlParameter("@phonemob", SqlDbType.BigInt);
        p6.Value = mobtxt.Text;
        cmd.Parameters.Add(p6);

        SqlParameter p7 = new SqlParameter("@opdate", SqlDbType.DateTime);
        p7.Value = optxt.Text;
        cmd.Parameters.Add(p7);

        SqlParameter p8 = new SqlParameter("@department", SqlDbType.VarChar,20);
        p8.Value = depddl.Text;
        cmd.Parameters.Add(p8);

        cmd.ExecuteNonQuery();
        cn.Close();

        Response.Redirect("outpatient.aspx");
    }
    protected void doctorddl_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}




Code at doctorsignup.aspx.cs
C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class doctorlogin : System.Web.UI.Page
{
    SqlConnection cn = new SqlConnection("server=IPOG-A95E1056D3;user id=sa;password=sqlserver;database=Hospitalmanagement");
    SqlDataReader dr;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        cn.Open();
        string qry;
        qry = "select * from hospital_doctorsignup where loginid='"+lidtxt.Text+"' and password='"+pwdtxt.Text+"'";
        SqlCommand cmd = new SqlCommand(qry, cn);
        dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            Response.Redirect("doctorsden.aspx");
        }
        else
        {
            pwdlb.Text = "Enter valid UserName/Password";
        }
    }
}



And the Error is

C#
Error	1	Type 'doctorsignup' already defines a member called 'Page_Load' with the same parameter types 



Some google say it cause by main page code so my main page code is

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

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

    }
}
Posted
Comments
Richard Deeming 30-Nov-15 8:21am    
Also, you appear to be storing passwords in plain text. That is an extremely bad idea. You should only ever store a salted hash of the user's password.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]
Our password hashing has no clothes - Troy Hunt[^]
Richard Deeming 30-Nov-15 8:23am    
Also, you're connecting to the database as sa. This is a special login with unrestricted access to the server, and should not be used for applications.

Connect to the server using a specific user which only has the permissions required for your application.

And if that's your real sa password that you've just posted to a public forum, then you need to change it immediately! (And next time, chose something a bit more secure!)

Why don't your class names match the page names? Regardless, partial classes are when you paste multiple physical files together. Changes are you are defining your doctorsignup class multiple times and more than one of those files has a definition for Page_Load. Search your entire code for "class doctorsignup" to find everywhere it is defined, and see if you have Page_Load defined more than once. Remove additional Page_Load methods so that it is only defined once.
 
Share this answer
 
The class name defined in outpatient.aspx.cs is doctorsignup.
The class name defined in doctorsignup.aspx.cs is doctorsignup.

You have two files defining parts of the same class. Both files have a Page_Load method.

Change the class name for outpatient.aspx.cs to something different. I would suggest outpatient, unless that conflicts with another class in your project.
 
Share this answer
 
Comments
Member 12175957 30-Nov-15 23:50pm    
I got the following error while applying this solution:

<pre lang="C#">Error 1 The name 'pttyddl' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\viewtests.aspx.cs 20 13 Mohan1
Error 2 The name 'pttyddl' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\viewtests.aspx.cs 21 13 Mohan1
Error 3 The name 'doctorddl' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\viewsurgeries.aspx.cs 21 13 Mohan1
Error 4 The name 'doctorddl' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\viewoperations.aspx.cs 21 13 Mohan1
Error 5 The name 'pidddl' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\surgeries.aspx.cs 21 13 Mohan1
Error 6 The name 'pttyddl' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\viewtests.aspx.cs 22 13 Mohan1
Error 7 The name 'doctorddl' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\viewappointments.aspx.cs 22 13 Mohan1
Error 8 The name 'type' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\patientinfo.aspx.cs 22 13 Mohan1
Error 9 The name 'pidddl' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\appointments.aspx.cs 22 13 Mohan1
Error 10 The name 'testddl' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\viewtests.aspx.cs 23 13 Mohan1
Error 11 The name 'testddl' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\viewtests.aspx.cs 24 13 Mohan1
Error 12 The name 'TextBox1' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\patientinfo.aspx.cs 24 104 Mohan1
Error 13 The name 'testddl' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\viewtests.aspx.cs 25 13 Mohan1
Error 14 The name 'lidtxt' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\emplogin.aspx.cs 25 68 Mohan1
Error 15 The name 'pwdtxt' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\emplogin.aspx.cs 25 103 Mohan1
Error 16 The name 'GridView1' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\patientinfo.aspx.cs 28 16 Mohan1
Error 17 The name 'GridView1' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\patientinfo.aspx.cs 29 13 Mohan1
Error 18 The name 'nametxt' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\empsignup.aspx.cs 29 19 Mohan1
Error 19 The name 'doctorddl' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\viewsurgeries.aspx.cs 31 9 Mohan1
Error 20 The name 'doctorddl' does not exist in the current context C:\Users\Kovit\Desktop\mix\hospita3\hospita3\4\Hospital Management System Source Code\viewoperations.aspx.cs 31 9 Mohan1
Error 21 The name 'ptntyp' does not exist in the current context
Richard Deeming 1-Dec-15 4:56am    
You need to correct the class name in the .aspx file as well as the .aspx.cs file.
Additional code for doctorsignup.aspx.cs


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

public partial class doctorsignup: System.Web.UI.Page
{
    SqlConnection cn = new SqlConnection("server=IPOG-A95E1056D3;user id=sa;password=sqlserver;database=Hospitalmanagement");
  protected void Page_Load(object sender, EventArgs e)
    {
         
    } 
    protected void subbtn_Click(object sender, EventArgs e)
    {
        cn.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "sp_hospital_doctorsignup";
        cmd.Connection = cn;


        SqlParameter p = new SqlParameter("@name",SqlDbType.VarChar,20);
        p.Value = nametxt.Text;
        cmd.Parameters.Add(p);

        SqlParameter p1 = new SqlParameter("@loginid",SqlDbType.VarChar,20);
        p1.Value = lidtxt.Text;
        cmd.Parameters.Add(p1);

        SqlParameter p2 = new SqlParameter("@password",SqlDbType.VarChar,20);
        p2.Value = pwdtxt.Text;
        cmd.Parameters.Add(p2);

        SqlParameter p3 = new SqlParameter("@department",SqlDbType.VarChar,20);
        p3.Value = depddl.Text;
        cmd.Parameters.Add(p3);

        SqlParameter p4 = new SqlParameter("@specialization",SqlDbType.VarChar,20);
        p4.Value = speddl.Text;
        cmd.Parameters.Add(p4);

        SqlParameter p5 = new SqlParameter("@phonenumber",SqlDbType.BigInt);
        p5.Value = phtxt.Text;
        cmd.Parameters.Add(p5);

        SqlParameter p6 = new SqlParameter("@address",SqlDbType.VarChar,20);
        p6.Value = addtxt.Text;
        cmd.Parameters.Add(p6);

        SqlParameter p7 = new SqlParameter("@email",SqlDbType.VarChar,20);
        p7.Value = emtxt.Text;
        cmd.Parameters.Add(p7);

        cmd.ExecuteNonQuery();
        cn.Close();
        Response.Redirect("doctorlogin.aspx");

    }
    protected void Resbtn_Click(object sender, EventArgs e)
    {
        Response.Redirect("doctorsignup.aspx");
    }
    protected void canbtn_Click(object sender, EventArgs e)
    {
        Response.Redirect("doctorlogin.aspx");
    }
}
 
Share this answer
 
Comments
Richard Deeming 30-Nov-15 8:16am    
To update your question, use the "Improve question" button to add the code to the question. DO NOT post the update as a solution to your question!

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