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