Solved

REQUIRE ASSISTANCE WITH LABEL CODE BEHIND

Posted on 2014-10-08
5
122 Views
Last Modified: 2014-10-14
Please review the attached code for "Label1" which is driving  the following error.   I need assistance in with the code behind.

Compiler Error Message: CS0111: Type 'Inspection' already defines a member called 'Page_Load' with the same parameter types

Source Error:
Line 86:
Line 87:
Line 88:     protected void Page_Load(object sender, EventArgs e)
Line 89:     {

 --------------------------------------------------------------------------------------------------------------------------------------------------
Code:

partial class Inspection : System.Web.UI.Page
{


    protected void btnSubmit_Click(object sender, System.EventArgs e)
    {

        SqlConnection con = new SqlConnection("");
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        con.Open();

       


        cmd.ExecuteNonQuery();
        con.Close();


        Response.Redirect("");
    }



    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            FillDropdown(CondBY);
            FillDropdown(InspBy1);
        }
    }
    //Filldrop down
    void FillDropdown(DropDownList ddl)
    {

        SqlConnection con = new SqlConnection("");//connection string;
        con.Open();

        SqlCommand cmd = new SqlCommand("select * from EmpData", con);
        SqlDataAdapter dap = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        dap.Fill(ds);
        ddl.DataSource = ds;
        ddl.DataTextField = "Name1";//Database table filed name for display in dropdown
        ddl.DataValueField = "EmpNo";//display in textbox when select dropdown field
        ddl.DataBind();
    }


    protected void CondBY_SelectedIndexChanged(object sender, EventArgs e)
    {
        EmpAP.Text = CondBY.SelectedValue.ToString();// get value form dropdown

    }
    protected void InspBy1_SelectedIndexChanged(object sender, EventArgs e)
    {
        EmpAP1.Text = InspBy1.SelectedValue.ToString();// get value form dropdown
    }



    protected void Page_Load(object sender, EventArgs e)
    {

        Label1.Visible = false;
       

        {


            if (CondBY.SelectedValue == "CONMX" && Conmx.Text == "")
            {
                Label1.Visible = true;
                Label1.Text = "Enter Name";
               


            }

        }
    }
}
0
Comment
Question by:BOEING39
  • 2
5 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40370112
Can you check your code since this error means that you have two  protected void Page_Load?
0
 

Author Comment

by:BOEING39
ID: 40371118
Yes that is the error I need assistance getting around this.   When "CONMX" is selected under the "ConBY" ddl I need "Label1" to display.   I am not sure of the code behind arrangement.  I am now receiving this error:

Compilation Error
  Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

 Compiler Error Message: CS0542: 'Inspection': member names cannot be the same as their enclosing type

Source Error:
Line 71:     }
Line 72:
Line 73:     partial class Inspection : System.Web.UI.Page
Line 74:    
Line 75:     {
 ------------------------------------------------------------------------------------------------------
CODE



protected void InspBy1_SelectedIndexChanged(object sender, EventArgs e)
    {
        EmpAP1.Text = InspBy1.SelectedValue.ToString();// get value form dropdown
    }

    partial class Inspection : System.Web.UI.Page
   
    {

    }
    protected void Page_Load(object sender, EventArgs e)
    {

        Label1.Visible = false;


        {


            if (CondBY.SelectedValue == "CONMX" && Conmx.Text == "")
            {
                Label1.Visible = true;
                Label1.Text = "Enter Name";



            }


        }
0
 
LVL 80

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 40374483
removed duplicate onload and moved into code page

partial class Inspection : System.Web.UI.Page
{
    protected void btnSubmit_Click(object sender, System.EventArgs e)
    {
        SqlConnection con = new SqlConnection("");
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        Response.Redirect("");
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            FillDropdown(CondBY);
            FillDropdown(InspBy1);
	     Label1.Visible = false;
            if (CondBY.SelectedValue == "CONMX" && Conmx.Text == "")
            {
                Label1.Visible = true;
                Label1.Text = "Enter Name";
            }
        }
        }
    }
    //Filldrop down
    void FillDropdown(DropDownList ddl)
    {
        SqlConnection con = new SqlConnection("");//connection string;
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from EmpData", con);
        SqlDataAdapter dap = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        dap.Fill(ds);
        ddl.DataSource = ds;
        ddl.DataTextField = "Name1";//Database table filed name for display in dropdown
        ddl.DataValueField = "EmpNo";//display in textbox when select dropdown field
        ddl.DataBind();
    }
    protected void CondBY_SelectedIndexChanged(object sender, EventArgs e)
    {
        EmpAP.Text = CondBY.SelectedValue.ToString();// get value form dropdown
    }
    protected void InspBy1_SelectedIndexChanged(object sender, EventArgs e)
    {
        EmpAP1.Text = InspBy1.SelectedValue.ToString();// get value form dropdown
    }
} 

Open in new window

0
 

Author Closing Comment

by:BOEING39
ID: 40380562
Worked.    Thx
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Service Controller 1 28
MediaHelp 4 26
What Does This C# Code Block Do? 5 57
custom authorization on controller action and HTML in asp.net mvc 1 29
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question