How can I pass an argument to a page so that when it opens it knows what to display?
Thanks,
Printable View
How can I pass an argument to a page so that when it opens it knows what to display?
Thanks,
Query strings or using POST (using C#):
Query String
www.mydomain.com/mypage.aspx?item=abc
Code:string myParam = Request.QueryString["item"];
POST
default.aspx (for e.g.):
mypage.aspx:Code:<form id="formName" method="post" action="mypage.aspx">
<input type="text" id="item" name="item" value="Blah">
</form>
[Edit] I changed the field name in the <form>, but not in the code behind :pCode:string myParam = Request.Form["item"];
Pass in a query string on the end of the url. Look at the address of this page, and you will see a query string after the .php and is started with the question mark.
example:
?s=&postid=1510457
Basically, this page is passing two parameters to the server: s and postid. The s variable isn't set to anything, but the postid is set to 1510457. The & symbol seperates values.
You use the Request.QueryString in your code to get these values. You can store them in a System.Collections.Specialized.NameValueCollection object if you want to make working with them easier.
Good luck.
I was slow...lol.