?
Solved

is inaccessible due to its protection level

Posted on 2004-09-25
2
Medium Priority
?
11,294 Views
Last Modified: 2011-08-18
Newbie to ASP.NET / C#

I just moved my code from inline to code behind and I am getting this error:

'newsDisplay.Prev_Click(object, System.EventArgs)' is inaccessible due to its protection level

Can someone tell me what it is I have declared wrong?  I imaginge its to do with public LinkButton btnPrev; but I thought public was about as unproteced as could be.

Thanks




Heres my aspx file:

<% @Page Language="C#" Debug="true" Src="NewsReader.cs" Inherits="newsDisplay" %>


<html>
      <head>
            <title>Paging with ASP.NET - DataSet Example - c#</title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      </head>
      <body>
            <form runat="server">
                  <font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><asp:label id="pageNumber" runat="server" /></font>
                  <asp:DataList id="theDataList" runat="server">
                        <ItemTemplate>
                              <h1><%# DataBinder.Eval(Container.DataItem, "NewsSubject") %></h1>
                              <%# DataBinder.Eval(Container.DataItem, "NewsContent") %>
                        </ItemTemplate>
                        <separatortemplate>
                              <hr color="#0099FF" />
                        </separatortemplate>
                  </asp:DataList>
      
                  <asp:LinkButton id="btnPrev" Text="&lt;" OnClick="Prev_Click" runat="server" />
                  <asp:LinkButton id="btnNext" Text="&gt;" OnClick="Next_Click" runat="server" />
            </form>
</html>


And the CS file:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

public class newsDisplay : Page
{
      PagedDataSource pagedData = new PagedDataSource();

       public LinkButton btnPrev;
       public LinkButton btnNext;
       public DataList theDataList;
 
      void Page_Load(Object obj, EventArgs e)
      {
            doPaging();
      }
      
      public DataTable getTheData()
      {
                  DataSet DS = new DataSet();
                  OleDbConnection strConnect = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\InetPub\\Database\\sixfive.mdb");
                  OleDbDataAdapter objSQLAdapter = new OleDbDataAdapter("SELECT * FROM News", strConnect);
                  objSQLAdapter.Fill(DS, "customers");
                  
                  return DS.Tables[0];
      }
      
      void doPaging()
      {
            pagedData.DataSource = getTheData().DefaultView;
            pagedData.AllowPaging = true;
            pagedData.PageSize = 5;
            
            try {
                  pagedData.CurrentPageIndex = Int32.Parse(Request["Page"].ToString());
            } catch (Exception ex) {
                  pagedData.CurrentPageIndex = 0;
            }
      
            btnPrev.Visible = (!pagedData.IsFirstPage);
            btnNext.Visible = (!pagedData.IsLastPage);
            
            theDataList.DataSource = pagedData;
            theDataList.DataBind();
      }
      
      void Prev_Click(Object obj, EventArgs e)
      {
            Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pagedData.CurrentPageIndex - 1));
      }
      
      void Next_Click(Object obj, EventArgs e)
      {
            Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pagedData.CurrentPageIndex + 1));
      }
}
0
Comment
Question by:mmc98dl1
2 Comments
 
LVL 8

Expert Comment

by:razo
ID: 12149641
try declaring the function prev_click as public
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 200 total points
ID: 12149724
Hi,

you have to replace these
     void Prev_Click(Object obj, EventArgs e)
     {
          Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pagedData.CurrentPageIndex - 1));
     }
     
     void Next_Click(Object obj, EventArgs e)
     {
          Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pagedData.CurrentPageIndex + 1));
     }
with
     public void Prev_Click(Object obj, EventArgs e)
     {
          Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pagedData.CurrentPageIndex - 1));
     }
     
     public void Next_Click(Object obj, EventArgs e)
     {
          Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pagedData.CurrentPageIndex + 1));
     }

Regards,
B..M
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

850 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