function is inaccessible due to its protection

I

Iain

Hi All

I have the code below (Using Delphi 2006 Developer to create an C#
ASP.Net page to update a simple database table. When the page is fired
I get the following error message

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Compiler Error Message: CS0122:
'LivLeadTime.WebForm2.Livery_DeleteCommand(object,
System.Web.UI.WebControls.DataGridCommandEventArgs)' is inaccessible
due to its protection level

Source Error:

Line 17:
Line 18: <div align="center">
Line 19: <asp:datagrid
Line 20: id="Livery"
Line 21: runat="server"

Source File: c:\inetpub\wwwroot\LivLeadTime\WebForm2.aspx Line: 19

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

As I am new to C# (or any C type language) I am finding this hard to
understand. Can anyone tell me what is wrong with this piece of code.

The code is below

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The WebForm2.aspx definitions for the form are

<asp:datagrid
id="Livery"
runat="server"
width="92%"
cellpadding="5"
font-size="8pt"
ondeletecommand="Livery_DeleteCommand"
autogeneratecolumns="false"
headerstyle-backcolor="black"
headerstyle-forecolor="white"
headerstyle-font-bold="true"
itemstyle-verticalalign="top"
oncancelcommand="Livery_CancelCommand"
onupdatecommand="Livery_UpdateCommand"
oneditcommand="Livery_EditCommand"
allowsorting="True"
onsortcommand="Livery_SortCommand">

<EditItemStyle borderstyle="Dashed"
bordercolor="#0000C0"
backcolor="#FFFFC0"></EditItemStyle>
<ItemStyle verticalalign="Top"></ItemStyle>
<HeaderStyle font-bold="True" forecolor="White"
backcolor="Black"></HeaderStyle>

<Columns>
<asp:EditCommandColumn
HeaderText="Edit"
EditText="Edit"
ButtonType="PushButton"
CancelText="Cancel"
UpdateText="Update">
</asp:EditCommandColumn>
<ASP:BoundColumn
datafield="LIVNAME"
headertext="Livery Name">
</ASP:BoundColumn>
<ASP:BoundColumn
datafield="LEADTIME"
headertext="Lead Time">
</ASP:BoundColumn>
<asp:buttoncolumn
Text="Delete"
HeaderText="Delete"
ButtonType="PushButton"
CommandName="Delete">
</asp:buttoncolumn>

</Columns>
</asp:datagrid>

and the WebForm2.aspx.cs code is as follows

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
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 LivLeadTime
{
/// <summary>
/// Summary description for WebForm2.
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid Livery;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if ((! IsPostBack))
{
}
else
{
}
}

#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.Livery.CancelCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.Livery_CancelCommand);
this.Livery.EditCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.Livery_EditCommand);
this.Livery.SortCommand += new
System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.Livery_SortCommand);
this.Livery.UpdateCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.Livery_UpdateCommand);
this.Livery.DeleteCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.Livery_DeleteCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion

private void Livery_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string LString = "Editing";
}

private void Livery_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string LString = "Deleting";
}

private void Livery_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
string LString = "Sorting";
}

private void Livery_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string LString = "Updating";
}

private void Livery_CancelCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string LString = "Cancelling";
}
}
 
M

Mark Fitzpatrick

The real confusing thing here is line 19. Line 19 is not just the
asp:datagrid definition however, line 19 refers to the entire element
definition. The problem will be further down the attribute list. I believe
the problem is going to be your reference to the commands such as
Livery_CancelCommand. In the codebehind file, you have Livery_CancelCommand
defined with the private access level. Change this to protected. Do the same
on your other event handlers that are used by the datagrid. The reason is,
since they are defined as private they will only be available from within
the codebehind itself and not on the actual asp.net page. Protected makes
them visibile to the asp.net page, but not publically available to the app
as a whole.
 
I

Iain

Hi Mark

Thanks for your help.
Changing the function to protected work.
However, what I cannot fathom is the event handler function was defined
as private by the Delphi 2006 developer ide. eg I double click teh
event in teh object inspector and it creates the event (as any standard
ide would do) so I would have thought that all would be well .
I will check the Borland site and see if therre are any updates

Thnaks againn

Iain
 
I

Iain

Hi Milosz

Thanks for your help Milosz.
What you pointed out certainly makes sense. I removed teh reference to
the event handlers from the datagrid definition, renamed the functions
from protected to private and it all works now.

Thanks a lot for your help

Iain
 
I

Iain

Hi Milosz

Both the ASP.Net 1.1 and the ASP.Net 2.0 methods work.
Which in you opinion is the best method to use or is there no
differnece apart from teh definition methodology.

Iain
 
G

Guest

Hi Iain,

It's up to you. i would use asp.net 2.0 method because you have to write
less lines of code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top