A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
PostBack to a different pageTutorial on how you can PostBack from one page to another. By default in ASP.NET 1.0 and 1.1 PostBack is done to the same page. We will see how we can get around this. Also, you will see how the PostBackUrl property in ASP.NET 2.0 makes this easier. |
On Saturday, August 6th 2005 at 11:49 AM By Andrew Pociu (View Profile) ![]() ![]() ![]() ![]() (Rated 4.3 with 12 votes) |
||||
Post form to another page in ASP.NET 1.0 and 1.1When posting a form in an ASP.NET page, it gets posted to itself. That means that when you press the submit button, the same page reloads, and you get the data using the if(IsPostBack) condition. But how about when you want to post the form to a different page. For example WebForm1.aspx has the form, and when the user presses the submit button you want it to be posted and the results to be shown in WebForm2.aspx. There's no easy way to do this in ASP.NET 1.1 (or 1.0). However, let's see first how this can be done in ASP.NET 1.x. When the submit button is pressed, instead of doing PostBack, you need to use the following line so that the second WebForm is loaded:
We don't use a normal redirection, instead we use Server.Transfer(), because we want the properties of WebForm1 to be accessible inside WebForm2. What properties? Well, we need to create properties for each element we have inside WebForm1 and we want to get the value of in WebForm2. So, to be able to access the elements of WebForm1 from WebForm2, we need to set up properties inside WebForm1 for the textboxes and any other form controls we have. Suppose we only have a TextBox inside WebForm1, we set a property so we can be able to retrieve it from WebForm2:
By defining this property we will be able to access the value of txtEmail from WebForm2. To get to this property from inside WebForm2, we first need to create a new instance of WebForm1:
Using the try/catch block we make sure that the page is opened because PostBack was performed on WebForm1 (the referrer is WebForm1) and not because the URL to WebForm2 was typed directly in the browser. This way we prevent an ugly error that can occur in case the WebForm2 isn't opened as a result of WebForm1 PostBack. Post form to another page in ASP.NET 2.0To test this, create a new ASP.NET Website, and another page so that you have a total of two pages: Default.aspx and Default2.aspx. Inside Default.aspx add a TextBox and a Button. Now change Button1's PostBackUrl property to Default2.aspx. Now we only need to take care of Default2.aspx, in which the content of the TextBox from Default1.aspx will be shown. Inside the Page_Load() event, this is the only code we need to use:
We first check to see if we got PostBack from WebForm1.aspx. Then we use the FindControl() to get the TextBox1 control back from WebForm1.aspx, and we cast it to a TextBox. We then display its content on the screen using Response.Write(). |
|||||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||||
|
|||||
Current Commentshjgdfsadh
dshffdhd
Related Tutorials
Related Source Code
ASP.NET Job Search