By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,002 Members | 1,333 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,002 IT Pros & Developers. It's quick & easy.

Simple Button Onclick error

P: n/a
Hello

Im using VS.NET and cant get this simple page to work.......... I get:

CS0122: 'dbtest.WebForm2.Button1_Click(object, System.EventArgs)' is
inaccessible due to its protection level

what's wrong, i clicked the Button1 on designform and it created that
onclick event.........
<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false"
Inherits="dbtest.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>
<form id="WebForm2" method="post" runat="server">
<asp:TextBox id="Email" runat="server" MaxLength="255"></asp:TextBox>
<asp:RequiredFieldValidator Runat="server" ID="reqEmail"
ControlToValidate="Email"
ErrorMessage="Error......"></asp:RequiredFieldValidator>
<br>
<asp:Button id="Button1" OnClick="Button1_Click" runat="server"
Text="Button"></asp:Button></form>
</body>
</HTML>
using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace dbtest

{

/// <summary>

/// Summary description for WebForm2.

/// </summary>

public class WebForm2 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.TextBox Email;

protected System.Web.UI.WebControls.RequiredFieldValidator reqEmail;

protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}
/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Button1.Click += new System.EventHandler(this.Button1_Click);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

private void Button1_Click(object sender, System.EventArgs e)

{
}

}

}
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

Either:

Remove OnClick="Button1_Click" from the html part

--or--

Remove the event subscription: this.Button1.Click += new
System.EventHandler(this.Button1_Click); *and* set the accessible level to
protected (recommended), public or internal for the method Button1_Click.

Greetings
Martin
"Lasse Edsvik" <la***@nospam.com> wrote in message
news:#D*************@TK2MSFTNGP12.phx.gbl...
Hello

Im using VS.NET and cant get this simple page to work.......... I get:

CS0122: 'dbtest.WebForm2.Button1_Click(object, System.EventArgs)' is
inaccessible due to its protection level

what's wrong, i clicked the Button1 on designform and it created that
onclick event.........
<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="dbtest.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>
<form id="WebForm2" method="post" runat="server">
<asp:TextBox id="Email" runat="server" MaxLength="255"></asp:TextBox>
<asp:RequiredFieldValidator Runat="server" ID="reqEmail"
ControlToValidate="Email"
ErrorMessage="Error......"></asp:RequiredFieldValidator>
<br>
<asp:Button id="Button1" OnClick="Button1_Click" runat="server"
Text="Button"></asp:Button></form>
</body>
</HTML>
using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace dbtest

{

/// <summary>

/// Summary description for WebForm2.

/// </summary>

public class WebForm2 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.TextBox Email;

protected System.Web.UI.WebControls.RequiredFieldValidator reqEmail;

protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}
/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Button1.Click += new System.EventHandler(this.Button1_Click);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

private void Button1_Click(object sender, System.EventArgs e)

{
}

}

}

Nov 18 '05 #2

P: n/a
Martin,

thx, that worked :)

/Lasse
"Martin Dechev" <de*******@hotmail.com> wrote in message
news:eb*************@TK2MSFTNGP11.phx.gbl...
Hi,

Either:

Remove OnClick="Button1_Click" from the html part

--or--

Remove the event subscription: this.Button1.Click += new
System.EventHandler(this.Button1_Click); *and* set the accessible level to
protected (recommended), public or internal for the method Button1_Click.

Greetings
Martin
"Lasse Edsvik" <la***@nospam.com> wrote in message
news:#D*************@TK2MSFTNGP12.phx.gbl...
Hello

Im using VS.NET and cant get this simple page to work.......... I get:

CS0122: 'dbtest.WebForm2.Button1_Click(object, System.EventArgs)' is
inaccessible due to its protection level

what's wrong, i clicked the Button1 on designform and it created that
onclick event.........
<%@ Page language="c#" Codebehind="WebForm2.aspx.cs"

AutoEventWireup="false"
Inherits="dbtest.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>
<form id="WebForm2" method="post" runat="server">
<asp:TextBox id="Email" runat="server" MaxLength="255"></asp:TextBox>
<asp:RequiredFieldValidator Runat="server" ID="reqEmail"
ControlToValidate="Email"
ErrorMessage="Error......"></asp:RequiredFieldValidator>
<br>
<asp:Button id="Button1" OnClick="Button1_Click" runat="server"
Text="Button"></asp:Button></form>
</body>
</HTML>
using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace dbtest

{

/// <summary>

/// Summary description for WebForm2.

/// </summary>

public class WebForm2 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.TextBox Email;

protected System.Web.UI.WebControls.RequiredFieldValidator reqEmail;

protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}
/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Button1.Click += new System.EventHandler(this.Button1_Click);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

private void Button1_Click(object sender, System.EventArgs e)

{
}

}

}


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.