C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




ASP.NET 2.0 - Reading TextBox Values from previous Webform - Passing value between Pages


Posted Date: 07 Mar 2007    Resource Type: Code Snippets    Category: ASP.NET WebForms

Posted By: Harish Ranganathan       Member Level: Gold
Rating:     Points: 10



One of the issues with ASP.NET 1.x versions was inability to post a Webform to another Webform and thereby inability to access the previous page's control values in a simpler way. With ASP.NET 2.0, webforms can be posted to a another webform and also controls can have a postback URL to another Webform. This combined with the PreviousPage property of the page can help retrieving values from the previous web page.

The code below shows the Form Declaration. Note the "PostBackURL" property of the Button Control.
Note that this is the Code for PageOne.aspx and there is no Code behind functionality associated and hence not included in the Code snippet.


PageOne.aspx


















Herebelow is the HTML Design for PageTwo.aspx where the PageOne.aspx is posted to.

PageTwo.aspx








Herebelow is the Code written in the Page_Load of the PageTwo.aspx to retrieve the value entered in the TextBox of PageOne.aspx. Note the two checks, Page.PreviousPage != null which helps in avoiding erros if the PageTwo.aspx is directly accessed and Page.PreviousPage.IsCrossPagePostBack to check if the previous page involved in Cross Page Postback.

PageTwo.aspx.cs


protected void Page_Load(object sender, EventArgs e)
{
if (Page.PreviousPage != null && Page.PreviousPage.IsCrossPagePostBack)
{
TextBox TextBox1 = (TextBox)PreviousPage.FindControl("TextBox1");
Label1.Text = "Hello, " + "" + TextBox1.Text + "" + "! Welcome to the Second Page !!";
}

}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Handling Enter Key in Multiple Sections of a Page - ASP.NET 2.0 Default Button for Panels
Previous Resource: ASP.NET 2.0 - Setting the Focus on a specific TextBox
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use