473,670 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

public fields in webforms

All the fields in webforms are automatically declared as protected.
If I change them to public, they are converted back to protected.

Why is this happening ?

Thanks

Nov 18 '05 #1
5 2003
Trebor,

The reason that's happening is that controls in your Webform cannot be
public. When you browse to a Webform, an instance of that class is
created. The request is served and a response is sent to the client. At
that point, the instance of your Webform is no longer accessible.
Therefore, it would be useless to have a public member of a Webform.
Protected is the correct access modifier.

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
ja******@online .microsoft.com

This post is provided "AS-IS" with no warranties and confers no rights.

--------------------
From: <Trebor>
Subject: public fields in webforms
Date: Thu, 8 Apr 2004 12:55:49 +0200
Lines: 9
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#h************ **@TK2MSFTNGP09 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
NNTP-Posting-Host: 195.26.139.69
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:2243 89
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet

All the fields in webforms are automatically declared as protected.
If I change them to public, they are converted back to protected.

Why is this happening ?

Thanks


Nov 18 '05 #2
Trebor,

The reason that's happening is that controls in your Webform cannot be
public. When you browse to a Webform, an instance of that class is
created. The request is served and a response is sent to the client. At
that point, the instance of your Webform is no longer accessible.
Therefore, it would be useless to have a public member of a Webform.
Protected is the correct access modifier.

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
ja******@online .microsoft.com

This post is provided "AS-IS" with no warranties and confers no rights.

--------------------
From: <Trebor>
Subject: public fields in webforms
Date: Thu, 8 Apr 2004 12:55:49 +0200
Lines: 9
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#h************ **@TK2MSFTNGP09 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
NNTP-Posting-Host: 195.26.139.69
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:2243 89
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet

All the fields in webforms are automatically declared as protected.
If I change them to public, they are converted back to protected.

Why is this happening ?

Thanks


Nov 18 '05 #3
I'm asking this question besause I found some articles on the web
which are recommending Server.Transfer for moving between forms.

Ex: // New public properties are defined in WebForm1:
public string TBText
{
get
{
return TextBox1.Text;
}
}
// Then on ButtonClick event, the other form is invoked

Server.Transfer ("WebForm2.aspx ");
----------------------------------------------------------

The destination form - WebForm2 is using code like this to access fields in
WebForm1.

WebForm1 Form1;
Form1 = (WebForm1) HTTP.Context.Ha ndler;
TextBox1.Text = Form1.TBText;

I was wonderig if I can avoid the step for creating public properties, by
declaring the fields in WebForm1 as public,
and then access their values in WebForm2 like:

Ex. 2

WebForm1 Form1;
Form1 = (WebForm1) HTTP.Context.Ha ndler;
TextBox1.Text = Form1.TextBox1. Text;
Is the approach in Ex1 Ok?

Is the approach in Ex2 Wrong and Why?

Thanks


"Jim Cheshire [MSFT]" <ja******@onlin e.microsoft.com > wrote in message
news:gF******** ******@cpmsftng xa06.phx.gbl...
Trebor,

The reason that's happening is that controls in your Webform cannot be
public. When you browse to a Webform, an instance of that class is
created. The request is served and a response is sent to the client. At
that point, the instance of your Webform is no longer accessible.
Therefore, it would be useless to have a public member of a Webform.
Protected is the correct access modifier.

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
ja******@online .microsoft.com

This post is provided "AS-IS" with no warranties and confers no rights.

--------------------
From: <Trebor>
Subject: public fields in webforms
Date: Thu, 8 Apr 2004 12:55:49 +0200
Lines: 9
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#h************ **@TK2MSFTNGP09 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
NNTP-Posting-Host: 195.26.139.69
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:2243 89X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet

All the fields in webforms are automatically declared as protected.
If I change them to public, they are converted back to protected.

Why is this happening ?

Thanks

Nov 18 '05 #4
I'm asking this question besause I found some articles on the web
which are recommending Server.Transfer for moving between forms.

Ex: // New public properties are defined in WebForm1:
public string TBText
{
get
{
return TextBox1.Text;
}
}
// Then on ButtonClick event, the other form is invoked

Server.Transfer ("WebForm2.aspx ");
----------------------------------------------------------

The destination form - WebForm2 is using code like this to access fields in
WebForm1.

WebForm1 Form1;
Form1 = (WebForm1) HTTP.Context.Ha ndler;
TextBox1.Text = Form1.TBText;

I was wonderig if I can avoid the step for creating public properties, by
declaring the fields in WebForm1 as public,
and then access their values in WebForm2 like:

Ex. 2

WebForm1 Form1;
Form1 = (WebForm1) HTTP.Context.Ha ndler;
TextBox1.Text = Form1.TextBox1. Text;
Is the approach in Ex1 Ok?

Is the approach in Ex2 Wrong and Why?

Thanks


"Jim Cheshire [MSFT]" <ja******@onlin e.microsoft.com > wrote in message
news:gF******** ******@cpmsftng xa06.phx.gbl...
Trebor,

The reason that's happening is that controls in your Webform cannot be
public. When you browse to a Webform, an instance of that class is
created. The request is served and a response is sent to the client. At
that point, the instance of your Webform is no longer accessible.
Therefore, it would be useless to have a public member of a Webform.
Protected is the correct access modifier.

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
ja******@online .microsoft.com

This post is provided "AS-IS" with no warranties and confers no rights.

--------------------
From: <Trebor>
Subject: public fields in webforms
Date: Thu, 8 Apr 2004 12:55:49 +0200
Lines: 9
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#h************ **@TK2MSFTNGP09 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
NNTP-Posting-Host: 195.26.139.69
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:2243 89X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet

All the fields in webforms are automatically declared as protected.
If I change them to public, they are converted back to protected.

Why is this happening ?

Thanks

Nov 18 '05 #5
Trebor,

You can't use method 1 because the variable will be out of scope. If you
want to use that method, you should declare the variable as a static
variable.

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
ja******@online .microsoft.com

This post is provided "AS-IS" with no warranties and confers no rights.
--------------------
From: <Trebor>
References: <#h************ **@TK2MSFTNGP09 .phx.gbl> <gF************ **@cpmsftngxa06 .phx.gbl>Subject: Re: public fields in webforms
Date: Fri, 9 Apr 2004 14:23:21 +0200
Lines: 97
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <uk************ **@TK2MSFTNGP09 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
NNTP-Posting-Host: 195.26.139.81
Path: cpmsftngxa06.ph x.gbl!cpmsftngx a10.phx.gbl!TK2 MSFTFEED01.phx. gbl!TK2MSFTNGP0 8
.phx.gbl!TK2MSF TNGP09.phx.gblXref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:2246 32
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet

I'm asking this question besause I found some articles on the web
which are recommending Server.Transfer for moving between forms.

Ex: // New public properties are defined in WebForm1:
public string TBText
{
get
{
return TextBox1.Text;
}
}
// Then on ButtonClick event, the other form is invoked

Server.Transfe r("WebForm2.asp x");
----------------------------------------------------------

The destination form - WebForm2 is using code like this to access fields in
WebForm1.

WebForm1 Form1;
Form1 = (WebForm1) HTTP.Context.Ha ndler;
TextBox1.Tex t = Form1.TBText;

I was wonderig if I can avoid the step for creating public properties, by
declaring the fields in WebForm1 as public,
and then access their values in WebForm2 like:

Ex. 2

WebForm1 Form1;
Form1 = (WebForm1) HTTP.Context.Ha ndler;
TextBox1.Tex t = Form1.TextBox1. Text;
Is the approach in Ex1 Ok?

Is the approach in Ex2 Wrong and Why?

Thanks


"Jim Cheshire [MSFT]" <ja******@onlin e.microsoft.com > wrote in message
news:gF******* *******@cpmsftn gxa06.phx.gbl.. .
Trebor,

The reason that's happening is that controls in your Webform cannot be
public. When you browse to a Webform, an instance of that class is
created. The request is served and a response is sent to the client. At
that point, the instance of your Webform is no longer accessible.
Therefore, it would be useless to have a public member of a Webform.
Protected is the correct access modifier.

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
ja******@online .microsoft.com

This post is provided "AS-IS" with no warranties and confers no rights.

--------------------
>From: <Trebor>
>Subject: public fields in webforms
>Date: Thu, 8 Apr 2004 12:55:49 +0200
>Lines: 9
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
>Message-ID: <#h************ **@TK2MSFTNGP09 .phx.gbl>
>Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
>NNTP-Posting-Host: 195.26.139.69
>Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
>Xref: cpmsftngxa06.ph x.gblmicrosoft.publ ic.dotnet.frame work.aspnet:224 389 >X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
>
>All the fields in webforms are automatically declared as protected.
>If I change them to public, they are converted back to protected.
>
> Why is this happening ?
>
>Thanks
>
>
>
>



Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3593
by: rachel | last post by:
Hi all, I am new in ASP.Net. I have a question on link multiple web forms together. Here is the scenario: I create an Index.aspx WebForm which consists of a banner and three navigator buttons as well as a body to load the content. It is exactly like a normal HTML page where there are banner, menu bar, and body to load content. In my case, there are three .aspx WebForms which I have to link them together in the Index.aspx page. So that...
1
1717
by: Paul R | last post by:
Hi, I have a Winforms application that access some SQLServer2000 stored procedures. I have now written some new Webforms pages to use some of the same stored procs. The Webforms use the SAME data access classes (all of my business logic and data access classes are in DLLs that are shared between the Winforms and Webforms).
2
1031
by: Craig Buchanan | last post by:
I have a datagrid w/ a textbox and a checkbox that are repeated for each row. I would like to be able to cycle thru each row in the datagrid during postback and determine these fields values. How should I proceed? Thanks, Craig Buchanan
3
234
by: | last post by:
All the fields in webforms are automatically declared as protected. If I change them to public, they are converted back to protected. Why is this happening ? Thanks
20
2892
by: Martin Rosén-Lidholm | last post by:
Although an impossible question to answer, I fell urged to raise it anyhow. Given a fairly complex ERP application scenario, what's your estimation for the X-ratio dev. time for WebForms app
2
1500
by: Piotr Karwatka | last post by:
Hi! I have a little problem an qeustion. In .NET Windows Forms I can do something like that: - i have forms - Form1 Form2, on first form i have TextBox1 control on 2nd form I have Button1 control - on second Form i can acces data from Form1 like that: for example: MessageBox.Show(Form1.TextBox1.Text);
0
1393
by: Joergen Bech | last post by:
Trying to implement my own webforms designer to be hosted in a WinForms environment. Basically: I know that mshtml is used in the VS.Net 2003 WebForms designer, but the HTML behind the scenes is not the same as what is found on the HTML tab, i.e. <asp:CheckBox id=" ... would be translated to something like
4
3934
by: 3Cooks | last post by:
I have a windows application written in Visual Basic 6.0 that is going to be redeveloped in dotNET. We are trying to decide if we should deploy using Webforms or Winforms and I need advice from someone who is not on my team. The VB 6.0 application is used by approximately 100 users. All users reside in-house. There is an existing external website that will use some of the same components but the two applications are separate. The...
5
4938
by: Bit byte | last post by:
Can I use C# (Winforms) to design a website?. I am from C/C++ background but know nothing about Internet programming. My understanding of WebForms are that they are similar to WinForms in that they give a WYSIWYG environment for designing user interfaces - however, all searches I have done on WebForms display the actual HTML, not a WYSIWYG environment. My questions (finally) then are.
0
1929
by: JM | last post by:
Hi, I have uploaded an application written in asp.net 2.0 on server. By web controls started giving Javascript error and I figured it out from discussion groups that I have to put WebForms.js file with the aspx pages. But I am unable to find out WebForms.js file in .NET 2.0 . I have searched my PC also (I have VS 2005 and .NET 2.0) but unable to find WebForms.js file.
0
8466
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8384
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8813
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6212
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4388
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1791
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.