Another way to pass multiple parameters in a JS String?

Posted by Laghaterohan under JavaScript on 11/16/2010 | Points: 10 | Views : 5962 | Status : [Member] | Replies : 2
Hello,

Any other way in which i can pass multiple parameters in a query string? Ok, let me explain i have a form wherein i have about 8 parameters which needs to be passed in a query string. However i find this is not a
correct approach doing so so can any one suggest me any other way of doing this? Currently for passing these 8 parameters i am using following code:

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "Test", "javascript:window.open('MyPage.aspx?report_name=MyReport&pm1="+txt1.text&pm2=txt2.text&..........more 6 parameters follow here + "');", true);


Please can any one suggest any other way of doing so?


Thanks !!

Best Regards,
Rohan Laghate



Responses

Posted by: Poster on: 11/17/2010 [Member] Starter | Points: 25

Up
0
Down
As you are using window.open that is client side so you do not have any better option. Another option you can do is that on click of the link call a JavaScript function, create cookies for all the variables using javaScript. On another page retrieve cookies and do your work.

See this article on how to create and read cookie in javascript http://www.w3schools.com/JS/js_cookies.asp

Thanks

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajbandi on: 9/5/2011 [Member] Starter | Points: 25

Up
0
Down
Thats not a straighforward solution with cookies.

The best solution is to create a dynamic form with javascript and post it to MyPage.aspx.

create a javascript function to create and post form in a new window

function PostForm()
{
var win = window.open('', "My Page posting")
var doc = win.document;

doc.writeln('<html><head><\/head>');
doc.writeln('<body onload="document.forms[0].submit()">');
doc.writeln("<form id='postform' name='postform' action='MyPage.aspx' method='post'>");
doc.writeln("<input type='hidden' name='param1' value='value1'>");
// Add required inputs here like the above statement.
doc.writeln("</form>");
doc.writeln('<\/body>');
// doc.writeln(s);
doc.writeln('<\/html>');
doc.close();
}

And change the above init script as below

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "Test", "PostForm()", true);


Thanks,
Raj

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response