Cross Page Posting ASP .NET - alternative to long and complicated query strings
Scenario: in my application, I have a page where I search for records. Let's say user accounts. I type the user name in a TextBox and hit Search. the results are displayed. If there is no available result, I want an 'Add New User' button to appear on the page, button that redirects the user to the page where you can insert new users and fill in the fields with the info i searched for in the previous page.
I don't like large and more or less explicit querystrings. That is why for the Add New user burron I will not perform Response.Redirect("NewUser.aspx?username=" + txtUsername.Text). Plus, what if I have 10 fields on the search page? The length of the query string has a limit and so does my focus :)
The solution is easy: I should just redirect to New User and read the information from the Previous Page.
Zis si facut. (word by word translation not supported :) )
There are 4 steps:
1. the Add New user Button:
< a s p : LinkButton ID =" lnkAdd" runat ="server" Visible ="False" PostBackUrl= "~ /NewUser.aspx" > Add New Patient < / asp : LinkButton>
2. the Search page code: add a public property that exposes the control(s) you want to look for when you are in the next page:
public TextBox TxtName
{
get { return txtName; }
}
3. the New User page:
< % @ PreviousPageType VirtualPath=" ~ / Search.aspx " % >
4. the code
if(PreviousPage.Title.Equals("Search"))
{
string name = PreviousPage.TxtName.Text;
}








Recent Comments
Starting form the sample I mentioned
Thanks for posting this. It sav
The left image does not overlap t
Was Looking for the "inline" and "at