-----------------------------------------------------------
New Message on MumbaiUserGroup
-----------------------------------------------------------
From: Swapnil_B1
Message 1 in Discussion
Server.Transfer & Server.Execute
I have got lots of queries in difference between Server.Transfer method and
Server.Execute method. I would like to share same in the Group.
Let's first look at each method in example. When transferring data from the
first page to the second page, the form values are available to the second page
through the current contexts HTTP handler, provided the server control or
property that is to be referenced is declared public. The execute method works
in a very similar way; the content is transferred through the current contexts
HTTP handler, which is available to the second page. The difference between the
two methods is that executing a page will insert the second pages content into
the first page, whereas transferring redirects to the second page, while still
referencing the first page in the browser's address bar.
'Simple statement in Page1 event (such as a link button click event)
Server.Transfer("transfer2.aspx", True)
OR
Server.Execute("execute2.aspx")
'Code in Page2s Page_Load event
Dim objForm As Page1 = CType(HttpContext.Current.Handler, Page1)
'transfer1's textbox controls are declared public
TextBox1.Text = objForm.TextBox1.Text
TextBox2.Text = objForm.TextBox2.Text
When dealing with the Transfer method, it may cause problems in an
application's navigation scheme. Although the attached code example doesn't
have that problem, I've experienced that issue when dealing with more complex
applications that involve a lot more page redirections.
When using the Transfer method, the second Boolean parameter allows the
transfer to not transmit the form data from the source form to the destination
form. In addition, the Execute method has an overloaded method that uses a
TextWriter object to write the HTML contents to. For example, using the
Page1/Page2 example, Page1 passes a TextWriter object in the Execute method.
The contents are written to this object, which is then written in the context
of Page1.
'Code in one of Page1's events (such as a link button click event);
'The TextWriter can then render the contents at any point in the page
'execution
Dim objWriter As System.IO.TextWriter
Server.Execute("execute4.aspx", objWriter)
Response.Write(objWriter.ToString())
'Code in Page2's Page_Load event
Dim objForm As execute3 = CType(HttpContext.Current.Handler, execute3)
Label1.Text = objForm.TextBox1.Text
Label2.Text = objForm.TextBox2.Text
Swapnil (Swaps)
http://swapsnet.spaces.live.com/
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/MumbaiUserGroup/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]