Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - ASP.Net javascript "focus" method needs to be called twice??

 
Thread Tools Search this Thread
Old 12-07-2004, 08:41 PM   #1
Default ASP.Net javascript "focus" method needs to be called twice??


Hello,

I am using the script below to open a new window and once opened, redirect to that open window from the original window:

private void btnNewPDFWindow_Click(object sender, System.EventArgs e)

{

string NewPage = "NewPageZoom.aspx";

string ScriptBlockNewPage = "<script language='javascript'>var
NewPDFPage=window.open('" + NewPage + "','PDFPage');";

ScriptBlockNewPage = ScriptBlockNewPage + "NewPDFPage.focus();</script>";

Response.Write(ScriptBlockNewPage);

}
For some reason, with the code above, I have to click the button twice in order to get it to focus to the 2nd window again.

Any ideas?

Regards,

TC




TC
  Reply With Quote
Old 12-07-2004, 09:12 PM   #2
John Timney \(ASP.NET MVP\)
 
Posts: n/a
Default Re: ASP.Net javascript "focus" method needs to be called twice??

At a guess, it might be running the focus code before the window has finished loading completely, on your second click the window is already loaded so the focu works.

Try putting a timer delay into the javascript to see if its that


--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"TC" <> wrote in message news:...
Hello,

I am using the script below to open a new window and once opened, redirect to that open window from the original window:

private void btnNewPDFWindow_Click(object sender, System.EventArgs e)

{

string NewPage = "NewPageZoom.aspx";

string ScriptBlockNewPage = "<script language='javascript'>var
NewPDFPage=window.open('" + NewPage + "','PDFPage');";

ScriptBlockNewPage = ScriptBlockNewPage + "NewPDFPage.focus();</script>";

Response.Write(ScriptBlockNewPage);

}
For some reason, with the code above, I have to click the button twice in order to get it to focus to the 2nd window again.

Any ideas?

Regards,

TC


  Reply With Quote
Old 12-07-2004, 09:15 PM   #3
=?Utf-8?B?QXJuZQ==?=
 
Posts: n/a
Default RE: ASP.Net javascript "focus" method needs to be called twice??

TC,
I would create a Literal Control and write the script text to that control.
Protected WithEvents script As System.Web.UI.WebControls.Literal
script.text = '<script language=javascript...........

Arne.

"TC" wrote:

> Hello,
>
> I am using the script below to open a new window and once opened, redirect to that open window from the original window:
>
> private void btnNewPDFWindow_Click(object sender, System.EventArgs e)
>
> {
>
> string NewPage = "NewPageZoom.aspx";
>
> string ScriptBlockNewPage = "<script language='javascript'>var
> NewPDFPage=window.open('" + NewPage + "','PDFPage');";
>
> ScriptBlockNewPage = ScriptBlockNewPage + "NewPDFPage.focus();</script>";
>
> Response.Write(ScriptBlockNewPage);
>
> }
> For some reason, with the code above, I have to click the button twice in order to get it to focus to the 2nd window again.
>
> Any ideas?
>
> Regards,
>
> TC
>
>

  Reply With Quote
Old 12-08-2004, 04:27 AM   #4
Lowell Heddings
 
Posts: n/a
Default Re: ASP.Net javascript "focus" method needs to be called twice??

Why wouldn't you change this to a client-side event? You have the button
as a server-side button, which means the page already has to be reloaded
just to show another page.

Change the button to a client-side button, and add the javascript code
as a script block(RegisterClientScriptBlock ). Change your javascript
routine to run as a function. Call the function from the client-side button.

If you need to focus the window, you have much more control over it that
way. You can put in a brief timeout after opening the window, and then
call the focus method... something like this(syntax?)

function OpenPDFPage() {
NewPDFPage=window.open('NewPageZoom.aspx','PDFPage ');
SetTimeout(5,'NewPDFPage.Focus()');
}

Much more reusable.

Lowell





TC wrote:
> Hello,
>
> I am using the script below to open a new window and once opened,
> redirect to that open window from the original window:
>
>
> private void btnNewPDFWindow_Click(object sender, System.EventArgs e)
>
> {
>
> string NewPage = "NewPageZoom.aspx";
>
> string ScriptBlockNewPage = "<script language='javascript'>var
> NewPDFPage=window.open('" + NewPage + "','PDFPage');";
>
> ScriptBlockNewPage = ScriptBlockNewPage +
> "NewPDFPage.focus();</script>";
>
> Response.Write(ScriptBlockNewPage);
>
> }
>
> For some reason, with the code above, I have to click the button twice
> in order to get it to focus to the 2nd window again.
>
> Any ideas?
>
> Regards,
>
> TC
>
>

  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump