473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1978
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.public.dotnet.framework.aspnet
NNTP-Posting-Host: 195.26.139.69
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:224389
X-Tomcat-NG: microsoft.public.dotnet.framework.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.public.dotnet.framework.aspnet
NNTP-Posting-Host: 195.26.139.69
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:224389
X-Tomcat-NG: microsoft.public.dotnet.framework.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.Handler;
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.Handler;
TextBox1.Text = Form1.TextBox1.Text;
Is the approach in Ex1 Ok?

Is the approach in Ex2 Wrong and Why?

Thanks


"Jim Cheshire [MSFT]" <ja******@online.microsoft.com> wrote in message
news:gF**************@cpmsftngxa06.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.public.dotnet.framework.aspnet
NNTP-Posting-Host: 195.26.139.69
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:224389X-Tomcat-NG: microsoft.public.dotnet.framework.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.Handler;
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.Handler;
TextBox1.Text = Form1.TextBox1.Text;
Is the approach in Ex1 Ok?

Is the approach in Ex2 Wrong and Why?

Thanks


"Jim Cheshire [MSFT]" <ja******@online.microsoft.com> wrote in message
news:gF**************@cpmsftngxa06.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.public.dotnet.framework.aspnet
NNTP-Posting-Host: 195.26.139.69
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:224389X-Tomcat-NG: microsoft.public.dotnet.framework.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.public.dotnet.framework.aspnet
NNTP-Posting-Host: 195.26.139.81
Path: cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTF EED01.phx.gbl!TK2MSFTNGP08
.phx.gbl!TK2MSFTNGP09.phx.gblXref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:224632
X-Tomcat-NG: microsoft.public.dotnet.framework.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.Transfer("WebForm2.aspx");
----------------------------------------------------------

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

WebForm1 Form1;
Form1 = (WebForm1) HTTP.Context.Handler;
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.Handler;
TextBox1.Text = Form1.TextBox1.Text;
Is the approach in Ex1 Ok?

Is the approach in Ex2 Wrong and Why?

Thanks


"Jim Cheshire [MSFT]" <ja******@online.microsoft.com> wrote in message
news:gF**************@cpmsftngxa06.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.public.dotnet.framework.aspnet
>NNTP-Posting-Host: 195.26.139.69
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
>Xref: cpmsftngxa06.phx.gblmicrosoft.public.dotnet.framework.aspnet:224389 >X-Tomcat-NG: microsoft.public.dotnet.framework.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
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...
1
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...
2
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. ...
3
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
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...
2
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...
0
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...
4
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...
5
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.