window.open

R

rbutch

hey guys i've got a question as to why something is happening.

basically building a web application, and i want to open up another .aspx form, but not
close the one i have.

so, i assign a button this.

MyButton.Attributes.Add("onclick", "window.open('MyForm.aspx');")

it works great but, it takes two clicks before it responds. i really do like the effect of the other .aspx file opening, leaving the main.aspx intact.
i was just wondering why, it takes "two-clicks".

the other thing i like is, it's minimal code.

does anyone know, why and is there a better solution, than the one i'm using?

thanks again

rik


**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
R

Riki

rik said:
hey guys i've got a question as to why something is happening.

basically building a web application, and i want to open up another
.aspx form, but not
close the one i have.

so, i assign a button this.

MyButton.Attributes.Add("onclick", "window.open('MyForm.aspx');")

it works great but, it takes two clicks before it responds. i really
do like the effect of the other .aspx file opening, leaving the
main.aspx intact. i was just wondering why, it takes "two-clicks".

the other thing i like is, it's minimal code.

does anyone know, why and is there a better solution, than the one
i'm using?

Where did you put this line of code? Was it in Page_Load, or was it in an
event handler?
It should be in Page_Load.
 
R

rbutch

it's basically in a click_event:

Private Sub btnHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHelp.Click
btnHelp.Attributes.Add("onclick", "window.open('Help.aspx');")
End Sub

i guess i'm a little confused on why this would be in page load, since it's based on a click event. but, i'm pretty new to web apps.

do you mean build a Load template like this?:

Private Sub btnHelp_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHelp.Load
btnHelp.Attributes.Add("onclick", "window.open('Help.aspx');")
End Sub


i changed to this and it's a one click now.

thanks
rik

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
R

Riki

rik said:
i guess i'm a little confused on why this would be in page load,
since it's based on a click event. but, i'm pretty new to web apps.

The reason is that the client script is only added after
the first Click event is handled on the server.

This means:
1) you click
2) server adds client script
3) you have to click again to activate the client script.

Hope this makes it clear for you.
 
M

Martin Eyles

Alternativley you could just put

onclick="window.open('Help.aspx');"

in the button's tag

ie.

<input type="button" value="Click This Button for Help"
onclick="window.open('Help.aspx');" />
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top