By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,678 Members | 2,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,678 IT Pros & Developers. It's quick & easy.

Open in new window

P: n/a
I have an ASP.Net page that does a Response.Redirect to a code-created url.
Is there any way to code the redirect to open a new window similar to the
Javascript window.open() ? Thanks.

David
Sep 5 '07 #1
Share this Question
Share on Google+
21 Replies


P: n/a
no. it must be done via javascript or clicking an anchor (with a target).

-- bruce (sqlwork.com)

David C wrote:
I have an ASP.Net page that does a Response.Redirect to a code-created url.
Is there any way to code the redirect to open a new window similar to the
Javascript window.open() ? Thanks.

David

Sep 5 '07 #2

P: n/a
Along these lines:

I want to have a button that when clicked opens a new window and loads a
specific page. I tried many things, but none worked:

1 - Surround the button with a hyperlink control and no text with
thehyperlink.
2 - put in onclick=http://yada
3 - put in onclick="javascript:Window.Open(yada, '_blank');"
4 - in the Page_Load put in myButton.Attributes.Add("OnClick",
"Window.Open('yada', '_blank')")
....and probably some more attempts.

Nothing worked. Any ideas anyone?

Shelly

P.S. Why didn't they simply have attributes in the button control for the
navigation and the target specification? Yes, they have a space for an
image in the hyperlink control, but that means we would have to have the
image of a button when there is already a button design by default.
"bruce barker" <no****@nospam.comwrote in message
news:Oq**************@TK2MSFTNGP06.phx.gbl...
no. it must be done via javascript or clicking an anchor (with a target).

-- bruce (sqlwork.com)

David C wrote:
>I have an ASP.Net page that does a Response.Redirect to a code-created
url. Is there any way to code the redirect to open a new window similar
to the Javascript window.open() ? Thanks.

David

Sep 5 '07 #3

P: n/a
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
Nothing worked. Any ideas anyone?
<input type="button" value="New" onclick="window.open
('http://www.javascript-coder.com/window-popup/javascript-window-open.phtml','mywindow');"
/>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 5 '07 #4

P: n/a

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ul**************@TK2MSFTNGP05.phx.gbl...
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
>Nothing worked. Any ideas anyone?

<input type="button" value="New" onclick="window.open
('http://www.javascript-coder.com/window-popup/javascript-window-open.phtml','mywindow');"
....and, oh yes, popups are enabled.
Sep 6 '07 #5

P: n/a

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ul**************@TK2MSFTNGP05.phx.gbl...
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
>Nothing worked. Any ideas anyone?

<input type="button" value="New" onclick="window.open
('http://www.javascript-coder.com/window-popup/javascript-window-open.phtml','mywindow');"
I did this and nothing happened. What I put in was:

<input type="button" value="AA" onclick="window.open('thefile.aspx',
'Company List');" />

I also put in a complete url to a page that exists on the web rather than
'thefile,aspx' (which is in the same directory as the page I ran). Nothing
at all happened when I clicked on "AA".

Shelly
Sep 6 '07 #6

P: n/a
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
>
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ul**************@TK2MSFTNGP05.phx.gbl...
>"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
>>Nothing worked. Any ideas anyone?

<input type="button" value="New" onclick="window.open
('http://www.javascript-coder.com/window-popup/javascript-window-open.phtml','mywindow');"

...and, oh yes, popups are enabled.

Have you accidentally disabled JavaScript...?

Also, have you unchecked the browser option to display a warning for all
errors...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 6 '07 #7

P: n/a

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:uN**************@TK2MSFTNGP05.phx.gbl...
>
Have you accidentally disabled JavaScript...?
No. Javascripts are enabled.
Also, have you unchecked the browser option to display a warning for all
errors...?
It is unchecked.

I verified these settings after your post and before I responded.

Shelly
Sep 6 '07 #8

P: n/a
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:uN**************@TK2MSFTNGP05.phx.gbl...
>>
Have you accidentally disabled JavaScript...?

No. Javascripts are enabled.
>Also, have you unchecked the browser option to display a warning for all
errors...?

It is unchecked.

I verified these settings after your post and before I responded.

Hmm - starting to run out of ideas now...

When your page loads, do you see a warning symbol in the bottom left-hand
corner of your screen? If so, there's an error somewhere on the page...

When you do a View Source and find the window.open code, does it "look
right"...? Specifically, are there any carriage returns where you aren't
expecting them...?

Can you create a new page with nothing but the button in question on it -
does it work then...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 6 '07 #9

P: n/a
Solved! I need to add "javascript:" before the "window.open" command, and
have the full url there.

Now, the next thing is that I want to open a new page in the current window
and pass the info from one of the controls. Also, I want to do this with a
button. In php, I have the button submit, test on that, and then do a

header("Location: new_page_url?acct=" . $_POST['acctNumber']);

That sends the the info from the control "acctNumber" via the tag "acct",
and it opens that page in the current window. I want to do the same thing
here (in aspx), extracting the value from the control acctNumber so that it
is known in the next page. How do I do that? (Remember, I am just learning
this stuff)

Shelly
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
>"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:uN**************@TK2MSFTNGP05.phx.gbl...
>>>
Have you accidentally disabled JavaScript...?

No. Javascripts are enabled.
>>Also, have you unchecked the browser option to display a warning for all
errors...?

It is unchecked.

I verified these settings after your post and before I responded.


Hmm - starting to run out of ideas now...

When your page loads, do you see a warning symbol in the bottom left-hand
corner of your screen? If so, there's an error somewhere on the page...

When you do a View Source and find the window.open code, does it "look
right"...? Specifically, are there any carriage returns where you aren't
expecting them...?

Can you create a new page with nothing but the button in question on it -
does it work then...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 6 '07 #10

P: n/a
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
>>Solved! I need to add "javascript:" before the "window.open" command,
and have the full url there.

Curious - that should only be required for pseudo-URLs i.e. making the
hyperlink run a bespoke JavaScript function...

????? I don't understand what you mean. I used:
onclick="javascript:window.open('the_page_url_incl uding_http');"
Yes, but you shouldn't have needed to use javascript: in front of
window.open...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 6 '07 #11

P: n/a
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
I guess I didn't mention it clearly enough about being in the same window.
OK, then, how do I get the value of a control from the caller page when I
am in the called page? As I have said, I have accomplished the navigation
(though I wish it weren't Javascript), but I need something to do what I
had done in php with $_GET.
OK - let's take a step back here...

Firstly, taking ASP.NET completely out of the equation for a second, there's
no requirement whatsoever to use JavaScript to move from one page to
another - that's what hyperlinks are for:
<a href='mysecondpage.aspx'>Second page</a>

Secondly, passing parameters from one page to the next can be easily
achieved via querystrings:
<a href='mysecondpage.aspx?ID=2'>Second page</a>

In the Page_Load of the second page:
int ID = Convert.ToInt32(Request.QueryString["ID"]);

Thirdly, in ASP.NET, if you want to persist data across pages, you have
several options:

1) You can still use the QueryString method

2) You can use postbacks and the Session object

3) In ASP.NET 2, you can do cross-page posting:
http://msdn2.microsoft.com/en-us/lib...39(vs.80).aspx

This is, essentially, submitting one page to another page...

Finally, the best advice I can give you is to completely forget about PHP -
none of it will be of any use to you in ASP.NET...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 7 '07 #12

P: n/a

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...

OK, Mark, I don't know where I am going wrong:

company.aspx:
<asp:Button ID="agents" runat="server" Text="Agents" OnClick="agents_Click"
/></asp:Button>

company.aspx.vb:
Sub agents_Click(ByVal sender As Object, ByVal e As Suystem.EventArgs)
Session["acct"] = acct.Text
Resume.Redirect(agents.aspx, false)
End Sub

agents.aspx.vb:
Sub Page_Load(ByVal sender As Object, ByVal e As Suystem.EventArgs)
accountNumber = Session["acct"].ToString()
Session.Remove["acct"]
End Sub
What I get is: BC30545: Property Access must assign to the property or use
its value
and it points to the Session["acct"] = acct.Text line. Note that there is a
control called acct in company.aspx

Shelly
Sep 7 '07 #13

P: n/a
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
OK, Mark, I don't know where I am going wrong:
accountNumber = Session["acct"].ToString()
accountNumber.Text = Session["acct"].ToString()

Assuming accountNumber is a TextBox control...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 7 '07 #14

P: n/a
Of couse the agents.aspx is inclosed in quotes (typo) in the redirect line.

I also tried commenting out the session variable statements and tried
"agents.aspx?acct=1106" and used the Request.QueryString("acct"). This
didn't give an exception (and took me to the page), but didn't set the
accountNumber.Text either.

Also, with the Redirect, the back button becomes disabled. Is this expected
?

Shelly
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
>
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...

OK, Mark, I don't know where I am going wrong:

company.aspx:
<asp:Button ID="agents" runat="server" Text="Agents"
OnClick="agents_Click" /></asp:Button>

company.aspx.vb:
Sub agents_Click(ByVal sender As Object, ByVal e As Suystem.EventArgs)
Session["acct"] = acct.Text
Resume.Redirect(agents.aspx, false)
End Sub

agents.aspx.vb:
Sub Page_Load(ByVal sender As Object, ByVal e As Suystem.EventArgs)
accountNumber = Session["acct"].ToString()
Session.Remove["acct"]
End Sub
What I get is: BC30545: Property Access must assign to the property or
use its value
and it points to the Session["acct"] = acct.Text line. Note that there is
a control called acct in company.aspx

Shelly

Sep 7 '07 #15

P: n/a

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
>OK, Mark, I don't know where I am going wrong:
> accountNumber = Session["acct"].ToString()
accountNumber.Text = Session["acct"].ToString()

Assuming accountNumber is a TextBox control...
It is.

Shelly
Sep 7 '07 #16

P: n/a
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
Of couse the agents.aspx is inclosed in quotes (typo) in the redirect
line.
And it's Response.Redirect, not Resume.Redirect - missed that in my previous
reply...
I also tried commenting out the session variable statements and tried
"agents.aspx?acct=1106" and used the Request.QueryString("acct"). This
didn't give an exception (and took me to the page), but didn't set the
accountNumber.Text either.
Request.QueryString("acct").ToString()
Also, with the Redirect, the back button becomes disabled. Is this
expected ?
No..
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 7 '07 #17

P: n/a

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ec**************@TK2MSFTNGP03.phx.gbl...
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
>Of couse the agents.aspx is inclosed in quotes (typo) in the redirect
line.

And it's Response.Redirect, not Resume.Redirect - missed that in my
previous reply...
>I also tried commenting out the session variable statements and tried
"agents.aspx?acct=1106" and used the Request.QueryString("acct"). This
didn't give an exception (and took me to the page), but didn't set the
accountNumber.Text either.

Request.QueryString("acct").ToString()
>Also, with the Redirect, the back button becomes disabled. Is this
expected ?

No..
(A)
I fixed it to Response.QueryString("acct").ToString()
and Response.Redirect("agents.aspx?acct=1106", false)

It (1) goes to that page, (2) the back button is there, and (3) nothing
shows in accountNumber.Text

(B)
Also, using the other method, why couldn't I set a session variable. It
complained about that line. When I put in that line and started typing
session, it filled out the word "Session". But after I put in the rest
andgot to the acct.Text part, it didn't present me with acct (or anything,
for that matter) when I started typing it. If I start a line with ac it
presents me with the control acct, just not after the 'Session["acct"] ='
start of the line.

So, I still have two problems.
Sep 7 '07 #18

P: n/a
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
Also, using the other method, why couldn't I set a session variable. It
complained about that line. When I put in that line and started typing
session, it filled out the word "Session". But after I put in the rest
andgot to the acct.Text part, it didn't present me with acct (or anything,
for that matter) when I started typing it. If I start a line with ac it
presents me with the control acct, just not after the 'Session["acct"] ='
start of the line.

Apologies, I think that's my fault...

I never go anywhere near VB.NET, so I sometimes forget the syntatical
differences...

If, instead of Session["acct"] you try Session("acct") does it work...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 7 '07 #19

P: n/a

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Shelly" <sh************@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
>Also, using the other method, why couldn't I set a session variable. It
complained about that line. When I put in that line and started typing
session, it filled out the word "Session". But after I put in the rest
andgot to the acct.Text part, it didn't present me with acct (or
anything, for that matter) when I started typing it. If I start a line
with ac it presents me with the control acct, just not after the
'Session["acct"] =' start of the line.


Apologies, I think that's my fault...
Man, he is human after all :-) I'll match your one against my [at least]
100.
>
I never go anywhere near VB.NET, so I sometimes forget the syntatical
differences...
I would have used C#, except that most of the jobs here seem to say VB.Net.
So, I went that way. (I tell you it is a bitch to go back and forth between
a sentence delimited language (C#, PHP, C, Java, etc.) and a card image [aka
lines] one (VB, Fortran, Basic). I always seem to leave of the ";" when I
flip back :-) )
>
If, instead of Session["acct"] you try Session("acct") does it work...?
Well, it didn't produce any errors, but it didn't get the value either.

In company.aspx.vb I have in the agents_Click subroutine:
Session("acct") = acct.Text
Response.Redirect("agents.aspx", False)

and in the agents.aspx.vb Page_load I have:
accountNumber.Text = Session("acct").ToString()
Session.Remove("acct")

and, yes, there is a TextBox control "acct" in company.aspx and there is a
TextBox control accountNumber in agents.aspx.

So, now there are two things that give the next page, but neither way gives
me either session variable or the passed variable.

Shelly
Sep 7 '07 #20

P: n/a
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
....

Mark, I figured it out. I went into the debugger and found that the
Page_Load routine in the target page was not firing. I figured out why. It
is because I did not have "Handles Me.Load" at the end of the subroutine
declaration.

In the process of the investigation, I also came across where I could read
the value of the previous page's control from within the target page. I
bookmarked that page for later study.

Thanks for all the help.

Shelly
Sep 9 '07 #21

P: n/a
"Sheldon Glickler" <sh*******@asap-consult.comwrote in message
news:13*************@corp.supernews.com...
Mark, I figured it out. I went into the debugger and found that the
Page_Load routine in the target page was not firing. I figured out why.
It is because I did not have "Handles Me.Load" at the end of the
subroutine declaration.
Ah... yet another reason to ditch VB.NET immediately and move to C#... ;-)
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 9 '07 #22

This discussion thread is closed

Replies have been disabled for this discussion.