Parent window keeps the focus! grrr

E

Elsa Luiz

Hi everyone,
I have this problem hope you could help me...
I have an A.aspx page with a button, when I click the button I would
like to open another window with containing B.aspx. The problem is
that the window B.aspx appears fine but the focus returns to the
parent (A.aspx), I would like the focus in B.aspx window.
When I click the button on A.aspx I execute the following code:

private void btMyButton_Click(object sender, System.EventArgs e)
{
Session["LineFileCode"] = tbLineFileCode.Text.Trim();
OpenWindow("B.aspx");
}

OpenWindow his a method:

public void OpenWindow(string strURL)
{
string sb;
sb = "<script language=javascript>";
sb = sb + "w=window.open('" + strURL + "','PopUp',
'width=200,height=200,scrollbars=yes,toolbar=no,menubar=no');";
sb = sb + "w.focus();";
sb = sb + "</script>";

if (!this.IsStartupScriptRegistered("OpenWindow"))
{
this.RegisterStartupScript("OpenWindow", sb.ToString());
}
}

Can you please give me some clue of what am I doing wrong?
Thanks a lot in advance!

Elsa
 
B

bruce barker

your setting the focus too soon. better to have the popup set the focus
itself.

note: with the next security release of IE, your code will not work anyway,
as it will be idendified as a unsolicated popup.


-- bruce (sqlwork.com)
 
E

Elsa Luiz

Thank you Bruce for your reply but that was not the problem. Brian
Bond (thanks Brian!) sent me an email saying that SmartNavigation
turned on can cause this behaviuor and he was rigth, I had
SmartNavigation turned on, I turned it off and it worked, I have now
the focus on my child window. But I also winned another problem :(
When in my child I click on a button I execute the following code:

RefreshParentWindow();
CloseWindow();

public void RefreshParentWindow()
{
string sb;
sb = "<script language=javascript>";
sb = sb + "window.opener.location.reload();";
sb = sb + "</script>";

if (!this.IsStartupScriptRegistered("RefreshParentWindow"))
{
this.RegisterStartupScript("RefreshParentWindow", sb.ToString());
}
}

public void CloseWindow()
{
string sb;
sb = "<script language=javascript>";
sb = sb + "window.close();";
sb = sb + "</script>";

if (!this.IsStartupScriptRegistered("CloseWindow"))
{
this.RegisterStartupScript("CloseWindow", sb.ToString());
}
}

The problem is that when I clicked the button my browser keep asking
me:
"The page cannot be refreshed without resending the information. Click
Retry to send the information again, or clcik cancel to return to the
page that you were trying to view."
If I click Retry my Child window appears again, if I click cancel also
:(

Any thougths?
Thanks!
Elsa


bruce barker said:
your setting the focus too soon. better to have the popup set the focus
itself.

note: with the next security release of IE, your code will not work anyway,
as it will be idendified as a unsolicated popup.


-- bruce (sqlwork.com)




Elsa Luiz said:
Hi everyone,
I have this problem hope you could help me...
I have an A.aspx page with a button, when I click the button I would
like to open another window with containing B.aspx. The problem is
that the window B.aspx appears fine but the focus returns to the
parent (A.aspx), I would like the focus in B.aspx window.
When I click the button on A.aspx I execute the following code:

private void btMyButton_Click(object sender, System.EventArgs e)
{
Session["LineFileCode"] = tbLineFileCode.Text.Trim();
OpenWindow("B.aspx");
}

OpenWindow his a method:

public void OpenWindow(string strURL)
{
string sb;
sb = "<script language=javascript>";
sb = sb + "w=window.open('" + strURL + "','PopUp',
'width=200,height=200,scrollbars=yes,toolbar=no,menubar=no');";
sb = sb + "w.focus();";
sb = sb + "</script>";

if (!this.IsStartupScriptRegistered("OpenWindow"))
{
this.RegisterStartupScript("OpenWindow", sb.ToString());
}
}

Can you please give me some clue of what am I doing wrong?
Thanks a lot in advance!

Elsa
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top