trying to close webform page

srivalli

Well-known member
Joined
May 4, 2005
Messages
189
Programming Experience
Beginner
in vb.net
we use me.close() to close the window.

in asp.net
how do we close webform
any suggestions
thanks
 
You can use javascript: self.close()

If you are closing it using an asp.net button then add attribute to button on page load event:

VB.NET:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.myButton.Attributes.Add("onclick", "self.close()")
End Sub

But I think that you wont be able to close the main form without alert box because of the security reasons.
 
qry in closing the form

when i am trying to close the form by writting the code
u mentioned
it is displaying the message box second time when i click the button
but not first time
why is it so
thanks
ManicCW said:
You can use javascript: self.close()

If you are closing it using an asp.net button then add attribute to button on page load event:

VB.NET:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.myButton.Attributes.Add("onclick", "self.close()")
End Sub

But I think that you wont be able to close the main form without alert box because of the security reasons.
 
Right you should add an attribute before you intend to click the button. Btw, you can do the same in many ways ... say you can make a classic JavaScript function for closing current window and then call it either through server side button (web forms) or through client side button (HTML input tag)
VB.NET:
[COLOR=darkgreen]'remove the empty spaces before and after "<>" if u want to use this func[/COLOR]
< script language="javascript" > 
function closewindow() {
mywindow=window.close()
}
< /script >

VB.NET:
< input type="button" value="Close the window" onclick="closewindow()" >




Regards ;)
 
Back
Top