Open in new window

D

David C

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
 
B

bruce barker

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

-- bruce (sqlwork.com)
 
S

Shelly

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.
 
S

Shelly

Mark Rae said:

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
 
M

Mark Rae [MVP]

Shelly said:
...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...?
 
S

Shelly

Mark Rae said:
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
 
M

Mark Rae [MVP]

No. Javascripts are enabled.


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...?
 
S

Shelly

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
 
M

Mark Rae [MVP]

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...
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)

You don't need to pass anything anywhere to do that... Instead use the
window.opener method to reference the "parent" window e.g.

var acctNumber = window.opener.document.getElementById('acctNumber').value;

http://www.google.co.uk/search?sour...GB220&q=window.opener.document.getelementbyid
 
S

Shelly

Mark Rae said:
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_including_http');"
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)

You don't need to pass anything anywhere to do that... Instead use the
window.opener method to reference the "parent" window e.g.

var acctNumber =
window.opener.document.getElementById('acctNumber').value;

Thanks. That is what I needed. The other part of my question I found by
research. It is to use location.replace instead of window.open.

Shelly
 
M

Mark Rae [MVP]

????? I don't understand what you mean. I used:
onclick="javascript:window.open('the_page_url_including_http');"

Yes, but you shouldn't have needed to use javascript: in front of
window.open...
 
S

Shelly

Mark Rae said:
You don't need to pass anything anywhere to do that... Instead use the
window.opener method to reference the "parent" window e.g.

var acctNumber =
window.opener.document.getElementById('acctNumber').value;

I'm a little dense here and need a little more kindergarten help. What I
want to do is to have the child page open with the value of "accountNumber"
from the parent page in the the Text value of the control called "acct". I
currently have a master file (with the head, etc.), the page file, and the
associated page VB file that has all the subroutines.

I put the following into the content area of the chold page associated with
the head placeholder in the parent page:

<script language="Javascript" type="text/Javascript">
function SetAccountNumber() {
var accountNumber =
window.opener.document.getElementById('acct').value;
}
</script>

The accountNumber text box in the child page is blank. It is not grabbing
the value of 'acct' in the parent. What do I have to put into the
accountNumber control, if anything, to make it have the proper value? I
tried to run the javascript with onload="SetAccountNumber" and a couple of
other attempts, but nothing worked.
 
M

Mark Rae [MVP]

I'm a little dense here and need a little more kindergarten help. What I
want to do is to have the child page open with the value of
"accountNumber" from the parent page in the the Text value of the control
called "acct". I currently have a master file (with the head, etc.), the
page file, and the associated page VB file that has all the subroutines.

I put the following into the content area of the chold page associated
with the head placeholder in the parent page:

<script language="Javascript" type="text/Javascript">
function SetAccountNumber() {
var accountNumber =
window.opener.document.getElementById('acct').value;
}
</script>

The accountNumber text box in the child page is blank. It is not grabbing
the value of 'acct' in the parent. What do I have to put into the
accountNumber control, if anything, to make it have the proper value? I
tried to run the javascript with onload="SetAccountNumber" and a couple of
other attempts, but nothing worked.


Woah!!!! Are we talking about a MasterPage / ContentPage relationship
here...? A window won't have an opener property unless it was opened by
window.open - navigating from page to page within the same window (with or
without MasterPages) isn't the same as opening a new browser window...
 
S

Shelly

Mark Rae said:
Woah!!!! Are we talking about a MasterPage / ContentPage relationship
here...? A window won't have an opener property unless it was opened by
window.open - navigating from page to page within the same window (with or
without MasterPages) isn't the same as opening a new browser window...

My setup is that all content page files refer to a master page file and have
an associated vb file. From one content page file (call it the parent) I
open the child content page file in the SAME browser window using Javascript
locate.replace. I want to get a value from the parent content page to use
in the child content page -- and I want it done when the page first loads.

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.

Shelly
 
M

Mark Rae [MVP]

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/library/ms178139(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...
 
S

Shelly

Mark Rae said:
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>

Yes, but! I want a button click to bring about the page change. When I
surround the button item with the hyperlink anchors, nothing happens. That
was the original problem.
Secondly, passing parameters from one page to the next can be easily
achieved via querystrings:
<a href='mysecondpage.aspx?ID=2'>Second page</a>

I know, and have done that before many times. That is what I had done with
the header command in PHP.
In the Page_Load of the second page:
int ID = Convert.ToInt32(Request.QueryString["ID"]);

The is the line I was looking for to get the passed value. Now, where do I
put that line in order for the control to have that value? Is it in the
Page_Load subroutine and set controlName.Text = 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

A pointer to this documentation, please? (In the meantime, I'll search the
net)
3) In ASP.NET 2, you can do cross-page posting:
http://msdn2.microsoft.com/en-us/library/ms178139(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...

I understand and agree. I only mention it because there are operations that
I performed there that I need to figure out how to do here, such as passing
data with a button click from one page to another.

Shelly

P.S. Thank you VERY much for all your help and patience so far.
 
M

Mark Rae [MVP]

Yes, but! I want a button click to bring about the page change. When I
surround the button item with the hyperlink anchors, nothing happens.
That was the original problem.

Ah right - yes, that's never going to work...
In the Page_Load of the second page:
int ID = Convert.ToInt32(Request.QueryString["ID"]);

The is the line I was looking for to get the passed value. Now, where do
I put that line in order for the control to have that value? Is it in the
Page_Load subroutine and set controlName.Text = ID?
Yes.
2) You can use postbacks and the Session object

A pointer to this documentation, please? (In the meantime, I'll search
the net)

page1.aspx:
========
<asp:Button ID="cmdPage1" runat="server" Text="Click me"
OnClick="cmdPage1_Click" />

protected void cmdPage1_Click(object sender, EventArgs e)
{
Session["PageArgs"] = "some text";
Response.Redirect("page2.aspx", false);
}


page2.aspx:
========

protected void Page_Load(object sender, EventArgs e)
{
MyTextBox.Text = Session["PageArgs"].ToString();
Session.Remove["PageArgs"];
}

N.B. the above is not particularly robust, and will throw an exception if
Session["PageArgs"] doesn't exist, but it should give you a start...
 
S

Shelly

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top