I have a MultiPage IE Web control on my ASPX as MultiPage1. I have changed where it is declared to include the key word static as protected static MultiPage MultiPage1; and is using the variable name MultiPage1 to access the instance. When I run the application
I get the error. CS0176: Static member 'WebApplication1.WebForm4.MultiPage1' cannot be accessed with an instance reference; qualify it with a type name instead. Could someone please let me know how to "qualify it with a type name".
Hi Lesio, If I use MultiPage instead of MultiPage1 and try to access the method of the MultiPage it will give me the error as expected as it should use MultiPage1 as the object. "An object reference is required for the nonstatic field, method, or property 'System.Web.UI.Control.Controls'
" My question is how do you (what is the syntax) qualify MultiPage1 with a type name?
I'd like to see more your code... But: this error says that you're trying to call a method or property for OBJECT when you've to call it for CLASS. There is special qualifier
static which says that some methods or properties can be called for class not for object.It means that you can call this method without creating an object with
new operator. Look at the sample:
public class MyClass
{
public static int MyFunction(int myParam)
{
// do something;
return anyValue;
}
}
And in your code you call:
int someValue = MyClass.MyFunction(7);
// calling in such ways generates an error:
// MyClass myObject = new MyClass();
// int someValue = myObject.MyFunction(7);
I do understand what you mean, but for some reason when I try to do it it gives the compiler I mentioned in my previous message. Let me show you what I'm trying to do in my code. I have a MultiPage control on my ASPX page and in the code behind file it is declared
as. protected Microsoft.Web.UI.WebControls.MultiPage MultiPage1; I'm trying to add a PageView to this and a user controls (using LoadControl(a.ascx) ) to the PageView dynamically, but what has happened is that every time I do a PostBack from this use control
(a.ascx) the Page re-initializes the MultiPage control and hence the PageView which I had added to it are no londer available after the postback. I have detailed out this problem in (www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=496884) to which I still
have not got a reply. So I tried declaring it as a static variable, protected static Microsoft.Web.UI.WebControls.MultiPage MultiPage1; But then it gives the error I mentioned in my very first post at runtime not at compile time. Let me give you a complete
listing of the code on the aspx and cs files. WebUserControl1.ascx is a user control with a single button on it and the button has a event which it will trigger. If you do not have the Microsoft.Web.UI.WebControls lib send me a mail at sanathdw@hotmail.com
and I can send it to you.
namespace PrototypeIMS
{
///
/// Summary description for WebForm1.
///
public class Default : System.Web.UI.Page
{
protected static Microsoft.Web.UI.WebControls.MultiPage MultiPage1;
protected Microsoft.Web.UI.WebControls.TabStrip TabStrip1;
protected static Microsoft.Web.UI.WebControls.PageView pv;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(Page.IsPostBack == false)
{
Tab t1 = new Tab();
t1.Text = "Home";
TabStrip1.Items.Add(t1);
pv = new PageView();
pv.Controls.Add(Page.LoadControl("WebUserControl1.ascx"));
MultiPage1.Controls.Add(pv);
}
}
#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);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
<link rev="stylesheet" href="http://localhost/PrototypeIMS/styles/site.css? type="text/css"
rel="stylesheet">
<form id="Form1" method="post" runat="server">
<iewc:tabstrip id="TabStrip1" runat="server"
TargetID="MultiPage1"
TabDefaultStyle="color: white; font-weight: bold; background-color: #9e2018; padding: 2px 5px 3px 5px; border-bottom:solid 1px #ff5240"
TabHoverStyle="color: white; background-color: #ff5240; border-color: #ff5240; border-bottom:solid 1px #ff5240"
TabSelectedStyle="background-color: #ff5240;">
I've made short investigation & everything is OK: your app works properly. Unfortunately not proper for you. I'll explain: PageView is not defined in .aspx page. It's declared & created in code-behind dynamically. But take a look, where... It's created under
!Page.IsPostBack condition. It means that WebUserControl1.ascx is loaded only on opening page. When your page do postback PageView object is not created and user control WebUserControl1.ascx is not loaded. Effect: it looks like MultiPage is recreated :)
Yes I agree that is what is happening. So That is why I tried to make the MultiPage object static but then I get the problem of "qualify it with a type name" thing. Also the Tab objects are NOT defined in the .aspx page so how come they appear correctly on
the page. Isn't the MultiPage1 object "static" because it is in the .aspx page, or does it create a new object every time the page is loaded. Why does it behave differently from the TabStrip to which I add Tabs? I also tried making the PageView object static
to get around the problem which you have mentioned above but since a new MultiPage1 object seems to be created evey time the page is loaded (first time or due to a post back) it does not have the PageView object which I add to it earlier after a postback.
Maybe you can help me out better If I let you know what I'm tryin to achieve. I'm trying to create a set of Tabs and MutiPages to go with it which will be loaded and popuated when the main page loads. After that I do not want to keep creating Tab or PageView
objects and populating them and adding them to the MultiPage or the TabStrip objects every time a postback happens. That will make it slower :-). It seems to work for the TabStrip but not for the MultiPage. The only other way I see to solve the problem I have
is to make the Page View objects static so that they are only created once (at initial page load) and add them to the MultiPage every time tha page is loaded (i.e. outside of the if(!IsPostBack) condition)
sanathwic
Member
90 Points
18 Posts
What does "qualify it with a type name" mean
Mar 08, 2004 06:05 AM|LINK
LesioS
Participant
1314 Points
265 Posts
Re: What does "qualify it with a type name" mean
Mar 08, 2004 07:26 AM|LINK
LesioS
sanathwic
Member
90 Points
18 Posts
Re: What does "qualify it with a type name" mean
Mar 09, 2004 02:41 AM|LINK
LesioS
Participant
1314 Points
265 Posts
Re: What does "qualify it with a type name" mean
Mar 09, 2004 06:46 AM|LINK
public class MyClass { public static int MyFunction(int myParam) { // do something; return anyValue; } }And in your code you call: Clear? If not, ask :)LesioS
sanathwic
Member
90 Points
18 Posts
Re: What does "qualify it with a type name" mean
Mar 12, 2004 12:49 AM|LINK
namespace PrototypeIMS { /// /// Summary description for WebForm1. /// public class Default : System.Web.UI.Page { protected static Microsoft.Web.UI.WebControls.MultiPage MultiPage1; protected Microsoft.Web.UI.WebControls.TabStrip TabStrip1; protected static Microsoft.Web.UI.WebControls.PageView pv; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if(Page.IsPostBack == false) { Tab t1 = new Tab(); t1.Text = "Home"; TabStrip1.Items.Add(t1); pv = new PageView(); pv.Controls.Add(Page.LoadControl("WebUserControl1.ascx")); MultiPage1.Controls.Add(pv); } } #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); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } } <link rev="stylesheet" href="http://localhost/PrototypeIMS/styles/site.css? type="text/css" rel="stylesheet"> <form id="Form1" method="post" runat="server"> <iewc:tabstrip id="TabStrip1" runat="server" TargetID="MultiPage1" TabDefaultStyle="color: white; font-weight: bold; background-color: #9e2018; padding: 2px 5px 3px 5px; border-bottom:solid 1px #ff5240" TabHoverStyle="color: white; background-color: #ff5240; border-color: #ff5240; border-bottom:solid 1px #ff5240" TabSelectedStyle="background-color: #ff5240;">LesioS
Participant
1314 Points
265 Posts
Re: What does "qualify it with a type name" mean
Mar 13, 2004 07:36 AM|LINK
LesioS
sanathwic
Member
90 Points
18 Posts
Re: What does "qualify it with a type name" mean
Mar 19, 2004 02:02 AM|LINK
LesioS
Participant
1314 Points
265 Posts
Re: What does "qualify it with a type name" mean
Mar 19, 2004 05:27 AM|LINK
LesioS
Mr_Menon
Member
13 Points
65 Posts
Re: What does "qualify it with a type name" mean
Jul 03, 2009 08:56 AM|LINK
Hi there,
Thanks for the message, it helped me for good, i was searching for same issue.
Cheers
Menon