This topic is locked
[SOLVED]

 Redirecting within button code

6/8/2016 10:05:23 AM
ASPRunner.NET General questions
Pete K author

I've been pulling my hair out all morning, trying to figure out why this line

MVCFunctions.HeaderRedirect("UserInformation","list");


not only doesn't work but appartenly halts all code execution (with no error or warning) when added to the "Server" tab of a custom button. I finally searched through the help file and found an example where a button redirect was accomplished using Javascript:

location.href="http://cnn.com";;


Okay, fine -- I can pass the data I need to the Client After part and use that. But my question is, why does [size="2"]MVCFunctions.HeaderRedirect not work here? I'm trying to understand what works where and why. [/size]

Pete K author 6/14/2016

Well apparently MVCFunctions.postvalue() also does not work in the context of the server-side code of a custom button. Neither does Request.QueryString. I don't understand how this works and why parts of the asp.net framework are unavailable in this context. It's as if the "OnServer" function exists apart from the page.

Sergey Kornilov admin 6/14/2016

Button's code is executed via AJAX. It doesn't submit the whole page but does a separate request to buttonhandler.cs file behind the scene, runs server code and returns results back to the main page. This is why you cannot use server side redirect or cannot use Request.QueryString. What you need to do is to pass value from the main page to button's code.
See example #6 at http://xlinesoft.com/asprunnernet/docs/inserting_button.htm on conditional redirects.

Pete K author 6/14/2016



Button's code is executed via AJAX. It doesn't submit the whole page but does a separate request to buttonhandler.cs file behind the scene, runs server code and returns results back to the main page. This is why you cannot use server side redirect or cannot use Request.QueryString. What you need to do is to pass value from the main page to button's code.
See example #6 at http://xlinesoft.com...ting_button.htm on conditional redirects.


Thank you, Sergey. Your explanation makes sense. I am trying to learn about how all the pieces fit together. So, I managed to get the querystring using JavaScript in the OnBefore function using some code I found:



var vars = [], hash;

var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

for(var i = 0; i < hashes.length; i++)

{

hash = hashes[i].split('=');

vars.push(hash[0]);

vars[hash[0]] = hash[1];

}
params["callingPage"] = vars["callingPage"];


This works, although there might be a simpler way. At any rate, the current problem is solved. Thanks again for the assist.