3

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 this.

ANP
  • 15,287
  • 22
  • 58
  • 79

3 Answers3

4

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.

Jeff Sternal
  • 47,787
  • 8
  • 93
  • 120
0

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")
{
....
}
live-love
  • 48,840
  • 22
  • 240
  • 204
0

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

Community
  • 1
  • 1
Ramiz Uddin
  • 4,249
  • 4
  • 40
  • 72