473,748 Members | 8,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

TC
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.EventArg s e)

{

string NewPage = "NewPageZoom.as px";

string ScriptBlockNewP age = "<script language='javas cript'>var
NewPDFPage=wind ow.open('" + NewPage + "','PDFPage');" ;

ScriptBlockNewP age = ScriptBlockNewP age + "NewPDFPage.foc us();</script>";

Response.Write( ScriptBlockNewP age);

}
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
Nov 19 '05 #1
3 1033
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" <ge**********@y ahoo.com> wrote in message news:eO******** ******@TK2MSFTN GP15.phx.gbl...
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.EventArg s e)

{

string NewPage = "NewPageZoom.as px";

string ScriptBlockNewP age = "<script language='javas cript'>var
NewPDFPage=wind ow.open('" + NewPage + "','PDFPage');" ;

ScriptBlockNewP age = ScriptBlockNewP age + "NewPDFPage.foc us();</script>";

Response.Write( ScriptBlockNewP age);

}
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
Nov 19 '05 #2
TC,
I would create a Literal Control and write the script text to that control.
Protected WithEvents script As System.Web.UI.W ebControls.Lite ral
script.text = '<script language=javasc ript...........

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.EventArg s e)

{

string NewPage = "NewPageZoom.as px";

string ScriptBlockNewP age = "<script language='javas cript'>var
NewPDFPage=wind ow.open('" + NewPage + "','PDFPage');" ;

ScriptBlockNewP age = ScriptBlockNewP age + "NewPDFPage.foc us();</script>";

Response.Write( ScriptBlockNewP age);

}
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

Nov 19 '05 #3
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(RegisterC lientScriptBloc k ). 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=wind ow.open('NewPag eZoom.aspx','PD FPage');
SetTimeout(5,'N ewPDFPage.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.EventArg s e)

{

string NewPage = "NewPageZoom.as px";

string ScriptBlockNewP age = "<script language='javas cript'>var
NewPDFPage=wind ow.open('" + NewPage + "','PDFPage');" ;

ScriptBlockNewP age = ScriptBlockNewP age +
"NewPDFPage.foc us();</script>";

Response.Write( ScriptBlockNewP age);

}

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

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1642
by: Stefano | last post by:
Hi, i want set focus element with element.focus() but i have always this exception: "focus() is not a function" Can you help me? Thanks I use Mozilla
3
1954
by: TC | last post by:
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";
2
2594
by: Darin | last post by:
I have an html page (warehouse.htm) that has 2 frames (header.aspx and checkstock.aspx). When warehouse.htm opens, and the other 2 aspx pages load, I want the cursor to be sitting on the first textbox (titem) in checkstock.aspx. How do I do that? I have tried setting the tabindex of titem to 0, but it made no difference. Thanks.
0
1505
by: Stefan De Schepper | last post by:
Dear NG, I created a gridlike usercontrol. When clicking on a cell a textbox (or other control, depending on the cell's editortype) is shown. When some other control gets the focus, the textbox is hidden. So far, no problem. But when the textbox is visible and, for instance, I click on a toolbarbutton, the textbox' Lostfocus event is not fired. The situation should be that wherever I click, apart from the cell or textbox itself, the...
3
2137
by: AnalogKid17 | last post by:
I have the following line of code in my start/login page: document.getElementById("txtLogin").focus(); When I run the website app through F5 (Debug, Start Debugging) it works fine (ie, focus on txtLogin). When I run with CTRL+F5 (Debug, Start without debugging) the focus defaults to the URL box. Can anybody unveil the mystery ?
1
2126
by: Robert Jones | last post by:
If my application doesn't have focus and someone clicks on the menu, the menu click is "lost" as the form gets focus, and the user then has to click on the menu a second time to actually activate the menu. Is there a way for this focus click to be ignored and the menu to respond immediately to the first click?
6
2223
by: =?Utf-8?B?Sm9obiBBdXN0aW4=?= | last post by:
The HP t5520 Windows CE based thin client comes with a browser called 'Internet Explorer' - iehp.exe. It appears to have Java script (Request.Browser.JavaScript = True). I want to use this browser in conjunction with a 'keyboard wedge' magnetic card reader (and no keyboard) to record the arrival of staff and to display information about the employees jobs for the day. The webform has a textbox that must maintain focus so that when a...
2
1914
by: amit | last post by:
Hello group, I'm having a problem with an HTML element performance. When I use focus() method to jump to an input text. I realize the cursor is on waiting on the 2nd column waiting for user to enter a number. This is the HTML part: <input id="id_Text_Octet1" type=text value="" maxlength="3" onkeyup="SomeFunction(event, this.id);" style="border:0;width: 25px"><span style="font-size:18px;">.</span>
8
5119
by: freeskier | last post by:
I have been using the following code to cycle through a subform and disable all textboxes on a form. If a textbox on the form has the focus when this is run I get error "can't disable a control when it has the focus." When I add a line like "txtTest.SetFocus" where txtTest is a textbox on the main form I still get the same error. How do I resolve this issue? Also, please note that I disable all controls on the subform. Private Sub...
5
2230
by: martin DH | last post by:
Morning, Here's my problem: I have a field (ResFileLocation) on a form (frmResolution) that inserts a record-specific value (record ID, date stamp, etc) through vba when it has gained focus. To help clarify, here is the basic code I am looking at: Private Sub ResFileLocation_GotFocus() Me!ResFileLocation = "Forms!!NoticeID & "R_" & Left(Date, 2) & Mid(Date, 4, 2) & Right(Date, 4) End Sub
0
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.