473,385 Members | 1,642 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,385 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 1977
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...

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.