Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to pass parameters to another aspx file with javascript?

Reply
Thread Tools

how to pass parameters to another aspx file with javascript?

 
 
Chris
Guest
Posts: n/a
 
      04-17-2009
Hi,

i want to redirect to another page like here below in asp.net, but in
javascript and without menubar, toolbar etc ... :

Response.Redirect(String.Format("/myserver/myapp.aspx?Item0={0}&Item1={1}",
param1, param2))


i tried this, but the parameters are not passed to the other page.

<script type="text/javascript">
function fen() {
var hd1 = param1
var hd2 = param2
x = "left=200,top=200,width=600,height=400,title=no,to olbar=no,
menubar=no,location=no,directories=no, scrollbars=yes"
a = window.open("/myserver/myapp.aspx?Item0={0}&Item1={1}", hd1,
hd2, "", x)
}
</script>


Thanks for help.
Chris.


 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      04-17-2009
Thanks.

Does it maybe exist a way in javascript to redirect like in vb.net but of
course with the toolbar properties etc .. instead of opening a second
window?

If not, i did self.close() in order to close the first window, but with IE
7, i get a message asking me whether i want to close it. Any way to avoid
that message?
Thanks again.
Chris

"Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
news:%(E-Mail Removed)...
> "Chris" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> I tried this, but the parameters are not passed to the other page.

>
> You're trying to use server-side syntax in JavaScript - that's never going
> to work. Also, don't forget the semi-colons...
>
> <script type="text/javascript">
> function fen(param1, param2)
> {
> x = "left=200,top=200,width=600,height=400,title=no,to olbar=no,
> menubar=no,location=no,directories=no, scrollbars=yes";
> a = window.open('/myserver/myapp.aspx?Item0=' + param1 + '&Item1='
> + param2, "", x);
> }
> </script>
>
> ClientScript.RegisterStartupScript(GetType(), "redirect", "fen(" + param1
> + ", " + param2 + ");");
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      04-17-2009
Sorry if i come back here, but there is still a problem:
1) i get "type expected", so i did GetType(string) (are there other types?)
2) the param are not passed. I can see in the address bar this:
http://laptop/myserver/myapp.aspx?It...tem1=undefined

I give the whole code:
Sub page_load()
....
param1="xxx"
param2="zzz"
ClientScript.RegisterStartupScript(GetType(String) , "redirect", "fen(" +
param1 + ", " + param2 + ");")
End Sub

<script type="text/javascript">
function fen(param1,param2) {

x = "toolbar=no, menubar=no,location=no,directories=no,
scrollbars=yes"
a = window.open("/myserver/myapp.aspx?Item0=" + param1 + "&Item1=" +
param2, "", x)
self.close()
}
</script>

Thanks again
Chris



"Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> "Chris" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> Does there maybe exist a way in JavaScript to redirect like in VB.NET but
>> of course with the toolbar properties etc .. instead of opening a second
>> window?

>
> window.location = 'page2.aspx';
> location.href = 'page2.aspx';
>
>
>> If not, I did self.close() in order to close the first window, but with
>> IE7, I get a message asking me whether i want to close it. Any way to
>> avoid that message?

>
> Not in this case.
>
> It used to be possible to exploit one of the many security holes in IE6 by
> using window.opener=null;window.close(); but this has been fixed in later
> versions of IE, and never worked reliably in Mozilla-based browsers
> anyway...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      04-18-2009
There's no string formatting like that in js....

a = window.open("/myserver/myapp.aspx?Item0="+hd1+"&Item1="+hd2, ...

You may need to encode the parameter values depending of what type of data
you're passing.

Tim

"Chris" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> i want to redirect to another page like here below in asp.net, but in
> javascript and without menubar, toolbar etc ... :
>
> Response.Redirect(String.Format("/myserver/myapp.aspx?Item0={0}&Item1={1}",
> param1, param2))
>
>
> i tried this, but the parameters are not passed to the other page.
>
> <script type="text/javascript">
> function fen() {
> var hd1 = param1
> var hd2 = param2
> x = "left=200,top=200,width=600,height=400,title=no,to olbar=no,
> menubar=no,location=no,directories=no, scrollbars=yes"
> a = window.open("/myserver/myapp.aspx?Item0={0}&Item1={1}", hd1,
> hd2, "", x)
> }
> </script>
>
>
> Thanks for help.
> Chris.
>



 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      04-18-2009
Hi Mark, you never sleep?

i still have a problem:

with this code below, i get
http://myserver/myapp.aspx?Item0=und...tem1=undefined

If i remove onload="fen()" in the <body> tag, i get a javascript error
('xxx' is not defined) and of course the second window will never be opened.


<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>

<script runat="server">
Sub page_load()
param1="xxx"
param2="zzz"
ClientScript.RegisterStartupScript(Me.GetType(), "redirect", "fen(" + param1
+ ", " + param1 + ");", True)
End Sub
</script>

<html><head><title>test</title></head>
<body onload="fen()">
</body>
<script type="text/javascript">
function fen(param1,param2) {

x = "toolbar=no, menubar=no,location=no,directories=no, scrollbars=yes"
a = window.open("/myserver/myapp.aspx?Item0=" + param1 + "&Item1=" + param2,
"", x)
}
</script>
</html>



"Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
news:u%(E-Mail Removed)...
> "Chris" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>
>> Sorry if i come back here, but there is still a problem:
>> 1) i get "type expected", so i did GetType(string)

>
> Please don't do that...
> http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx
>
>
>> (are there other types?)

>
> No.
>
>
>> 2) the param are not passed. I can see in the address bar this:

>
> Sorry, I hadn't considered / realised that you were using VB.NET instead
> of C#...
>
> In which case, it's probably something like:
>
> ClientScript.RegisterStartupScript(Me.GetType(), "redirect", "fen(" +
> param1 + ", " + param2 + ");", True)
>
> You may also need to surround the params with single quotes in the
> JavaScript...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      04-18-2009
Ok, i removed onload="fen()" in the <body> tag.

I tried this:
ClientScript.RegisterStartupScript(Me.GetType(), "redirect", "fen(" + param1
+ ", " + param2 + ");", True)
this gives a javascript error: 'xxx' is not defined. This means that the
parameters are not passed from the server to javascript, no?

then this:
ClientScript.RegisterStartupScript(Me.GetType(), "redirect", "fen(" + param1
+ ", " + param2 + ");", False)
no javascript error; but the target window is not opened

then this:
ClientScript.RegisterStartupScript(Me.GetType(), "redirect", "fen(" + param1
+ ", " + param2 + ");")
same: no javascript error; but the target window is not opened

Sorry, I really don't see what' wrong ...

"Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> "Chris" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> If I remove onload="fen()" in the <body> tag, I get a JavaScript error
>> ('xxx' is not defined)

>
> ???? You don't need the onload line! The whole point of the ClientScript
> method is that it injects the JavaScript into the page as it is built on
> the server...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      04-18-2009
Thanks, it's ok now.

"Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> "Chris" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> Sorry, I really don't see what's wrong ...

>
> 1) The param1 and param2 variables weren't being instantiated...
>
> 2) There was no server-side form tag...
>
> 3) The string variables being passed to the JavaScript function didn't
> have single quotes around them...
>
>
> <%@ Page Language="VB" %>
> <%@ Import Namespace="System.IO" %>
>
> <script runat="server">
> Sub Page_Load()
> Dim param1 As String = "xxx"
> Dim param2 As String = "zzz"
> ClientScript.RegisterStartupScript(Me.GetType(), "redirect",
> "fen('" & param1 & "', '" & param2 & "');", True)
> End Sub
> </script>
>
> <html>
> <head>
> <title>test</title>
> <script type="text/javascript">
> function fen(param1,param2)
> {
> x = "toolbar=no, menubar=no,location=no,directories=no,
> scrollbars=yes"
> a = window.open("/myserver/myapp.aspx?Item0=" + param1 + "&Item1="
> + param2, "", x)
> }
> </script>
> </head>
> <body>
> <form ID="form1" runat="server" />
> </body>
> </html>
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: how to pass parameters to another aspx file with javascript? Jesse Houwing ASP .Net 0 04-19-2009 11:48 PM
how to pass a variable from test.aspx.vb to test.aspx? Chris ASP .Net 1 05-11-2006 07:14 PM
How to Pass values between from a popup page aspx & a normal page aspx Marco Antonio Montalvo Durán ASP .Net 2 01-23-2004 09:35 PM
including one aspx file in another aspx file vish ASP .Net 2 07-16-2003 10:29 PM



Advertisments