Hi Carlo,
Thanks for posting in the community!
From your description, currently you add a clientside "onclick" event for a
server button which will open a ne w browser window. However, now you'd
like to do some serverside operations before execute the clientside
script(open a browser window) yes?
If there is anything I misunderstood, please feel free to let me know.
As for this question, I quite agree to Suresh's suggestion that we can
register the clientside script(open a new browser window) in the certain
button's serverside click even handler after you've finished some certain
operations. Then, after the page turns back to client, the new browser
window will be opened. For example, the button's server click event is as
below:
private void btnSearch_Click(object sender, System.EventArgs e)
{
//do some operations here
string script = "<script
language=\"JavaScript\">window.open('
http://www.google.com');</script>";
Page.RegisterStartupScript("tempscript",script);
}
To make it clearly, I've made a sample page to show this means, you may
have a look if you feel anything unclear above:
-------------------aspx page------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="
http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language="javascript">
function checkField()
{
if(document.all("txtMain").value.length>4)
{
document.all("btnPostBack").click();
}
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td><FONT face="ËÎÌå"></FONT></td>
</tr>
<tr>
<td><FONT face="ËÎÌå">
<asp:Button id="btnSearch" runat="server"
Text="Search"></asp:Button></FONT></td>
</tr>
</table>
</form>
</body>
</HTML>
-----------------code behind class --------
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnSearch;
private void Page_Load(object sender, System.EventArgs e)
{
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnSearch_Click(object sender, System.EventArgs e)
{
//do some operations here
Response.Write("<br>Page is posted back at: "+
DateTime.Now.ToLongTimeString());
string script = "<script
language=\"JavaScript\">window.open('
http://www.google.com');</script>";
Page.RegisterStartupScript("tempscript",script);
}
}
---------------------------------------------
Please check out the above things. If you have any further quesitons or
need any help, please feel free to post here.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)