0

I have a page "article.aspx" .I insert a button in this page and i want after click on this button a value added to the url for example article.aspx?id=67 .

The important thing is how can i do this without redirect method?

   response.redirect("article.aspx?id=67")

thank you .

Tim
  • 4,051
  • 10
  • 36
  • 60
SSC
  • 301
  • 1
  • 4
  • 18
  • You cannot take the user to a different URL without redirecting. – SLaks Feb 11 '14 at 19:31
  • I don't want to change the url ,i just want to add a value to the current url – SSC Feb 11 '14 at 19:32
  • 1
    That's exactly what `change` means. – SLaks Feb 11 '14 at 19:33
  • I need to send value to current page – SSC Feb 11 '14 at 19:33
  • Please explain why you want to do that? May be what you are asking isn't needed. – gbs Feb 11 '14 at 19:39
  • I need to do 2 operations in a same page "article.aspx" i need to transfer result of operation one to execute operation 2 – SSC Feb 11 '14 at 19:44
  • Could you dynamically change the postbackURL? – Tim Feb 11 '14 at 20:01
  • from what you said, say you click a button and that is operation1, then you can in the button click set the value you want and pass it to operation 2. – gbs Feb 11 '14 at 20:42
  • Am I the only one thinking that passing the value in the URL is a bad idea? Wouldn't it be better to pass the value through a POST? I know when I see id=67 in my address bar, I tend to go change the id value to see what will come up. So if you are dealing with PHI and id=67 is user id 67, then entering id=66 will get you someone else's personal data. – TimWagaman Feb 11 '14 at 20:50
  • Querystrings are ubiquitous. It's a good idea to confirm it's a valid option on the inbound side, but if you work hard enough you can mess with pretty much anything that gets passed back and forth. There's really no way around it. – Tim Feb 11 '14 at 21:07

1 Answers1

1

Try updating your PostbackURL.

In your codebehind, you could do something along the lines of (assuming your link has the ID myLink)

If you want to post the form data back to the next page:

if (condition == true) 
{
 myLink.PostbackUrl = "article.aspx?id=67";
}

If you want to just go to the next page without posting the form, you'd use

if (condition == true) 
{
 myLink.NavigateUrl = "article.aspx?id=67";
}

You'll need to modify this based on what you're trying to do, but this is really the only way I can think of to do what you need to.

Tim
  • 4,051
  • 10
  • 36
  • 60
  • myLink would be either an ASP.NET HyperLink control or a LinkButton control. You need something on the page for the user to click for this to work if you can't use a redirect. Depending on which one you use you may expose either the NavigateURL or PostbackUrl properties. – Tim Feb 11 '14 at 20:31