Url editing on postback
Suppose I am having an url like: http://localhost:4647/Project/MyList.aspx.
On postback I want add some parameter(pageNo=4) to the url like: http://localhost:4647/Project/MyList.aspx?pageNo=4
Can I add "pageNo=4" to the url on postback as shown above? If yes please tell me how to do thi开发者_如何学编程s.
You cannot change the client's URL from server-side code without redirecting.
Clients don't normally read URLs from server responses. (An HTTP response doesn't even contain the URL, except when redirecting; see here and here for details.)
Having said that, redirecting after posting is a very good idea anyway - consider using that technique.
Set the form
method
type define to get
and keep a hidden
input
with 4
value and name pageNo
. Assuming you have done this at: http://localhost:4647/Project/MyList.aspx.
<html>
<body>
<form method="get">
<input name="pageNo" type="hidden" value="4"/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
In other case, if we assume that we standing on a different page and moving from there to MyList.aspx
then define action
attribute of form. We call that page Default.aspx
<html>
<body>
<form method="get" action="MyList.aspx">
<input name="pageNo" type="hidden" value="4"/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
Here, we just defined action
attribute of the form
.
And you should know when to use get
and when to post
Another thing you can try: you can use a hidden input and set the value on server side, and read it on the client side.
Server:
hdnPageNumber.Value = "4";
Client:
<asp:HiddenField id="hdnPageNumber" runat="server" ClientIDMode="Static" />
if ($('#hdnPageNumber').val() == "4")
{
....
}
精彩评论