ferguson_jerald
asked on
How to close a window on click event using c#?
Hello Experts.
I have a button on a web form that I would like to close the window when clicked. I am using VS2012 and c#.
I am attempting to use the following:
Am I missing a using directive?
Any help would be greatly appreciated.
I have a button on a web form that I would like to close the window when clicked. I am using VS2012 and c#.
I am attempting to use the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace case
{
public partial class frm1_new_case : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e)
{
}
private void btn_close_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Unfortunately I keep getting the following error:'case.frm1' does not contain a definition for 'Close' and no extension method 'Close' accepting a first argument of type 'case.frm1' could be found (are you missing a using directive or an assembly reference?)
Am I missing a using directive?
Any help would be greatly appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Andy, but that doesn't work. Lokesh, the Response.Redirect didn't accomplish what I needed either. However, I was able to find the answer on another site. The following does exactly what I needed:
String x = "<script type='text/javascript'>window.opener.location.href='**Your new url of new page after completing test**';self.close();</script>";
ScriptManager.RegisterClientScriptBlock(this.Page,this.Page.GetType(), "script", x,false);
Thanks,
J
Thanks, but as my suggestion didn't work I've asked all the points should go to the other expert.
this.Form.Close();