ASP.NET PostBackUrl and OnClick

arthrex used Ask the Experts™
Hi experts,

In my webform would like to make use of the postbackurl functionality. The problem is though that I also need to process data on the page before the postback to the other page. I googled and read that this is not possible.
I thought of a workaround where you have one button with the regular onClick method where I process data and a second button which has the postbackurl functionality. After I process data clicking the first button then I would call the second button in the code behind. But how do I cause the second button to do its postbackurl property in the code behind?
Would that workaround work?
What other suggestions do you have?

Thanks a lot
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
inside the OnClick() event handler. Process the reqired data and redirect to the desired URL like below..

protected void button_onclick(Object sender, EventArgs e)
  //do all data processing here..

  //give your URL here..


But then it's a redirect and not a cross-postback. I like the idea of cross-post-back because in the destination page I can find out if the user really came from the source page or just typed in the url manually. You can't check that with Response.Redirect
Add a normal postback event handler, then either use a onclientclick - call a javascript function (or as I prefer attach a javascript handler to the button using jquery), at the end of the javascript function return true, it should then still postback.

This is how confirm dialog popups work - to let the user decide if a postback should occur or not as it will return false if the user selects no.
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

For this, you can maintain a session variable to check, whether the user has logged in..

> I like the idea of cross-post-back

Just to nitpick: a postback is by definition to the same page (that is why it is called a postback). "Cross-post-back" is nonsense. It is just a post.
If the page you want direct to is on the same domain you can use Server.Transfer to send the entire request instead of just doing a Redirect.

This will not work cross-domain though.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial