I want to get the [browser] close button event in my web app.
I know how to get it client side by javascript but there are some problems within.
Is it possible to get this event server side in my web app?
Thanks
Can't be done through server code, but you can add some code on your server-side event which adds <script type="text\javascript">window.close();</script> when it finishes.
Have a look at ClientScriptManager.RegisterClientScriptBlock.
Related
In my C# code behind file I want to init a window on the client?
Ie. Window.open();
This should be fed with DialogTitle and DialogText and sent to the client.
I can set the window in the HTML and hide it until .open(); is called?
Is this task even possible Server side?
You can't call anything on the client from the server. However, you can send code to do so, for example JavaScript code or just plain HTML. If you are using ASP.NET Web Forms, the Page.RegisterClientScriptBlock method can be useful.
When you render the page, or a AJAX callback, put some <script> element in there with the code to open the window. Then you are all set. If it is an AJAX call, you have to execute the script, which is a little harder than just rendering the script element. See here how to do that.
I have a multiview: view1 contains a button and view2 contains the silverlight app - basically a button.
Pressing the asp:button in view1 takes you to view2 and the silverlight app is activated.
How do I make the click of the button in the silverlight app take me back to view1.
I tried to use a WCF service with aspnetcompatibility enabled but that has not yielded results since httpcontext.current.response is null.
Maybe I should use an httphandler?
I was wondering if someone could guide me in the right direction.
Thanks.
You can write a javascript method in the Silverlight hosting page and you can invoke the JS method using
HtmlPage.Window.Invoke("YourJSMethod", parameter);
In the YourJSMethod() javascript method you can write the logic to load the view 1 back.
when user close the web site that time i need to call some function here, what was the event for user close the page or browser in asp.net(C#).
You cannot do this with asp.net. The server does not know when the user closes the window. However you can use javascript, and attach an beforeunload event to the body tag.
window.onbeforeunload = function (e) {
//javascript code here
}
Here is a good SO thread on how this can be achieved.
There is no event in asp.net that could catch the event of user closing the window, because that happens on client-side. Your C# code runs on the server without any knowledge of the client's software.
There are some mechanisms using javascript and sending some data using ajax, but no one should rely on that.
I have this code implemented in my application, but whenever i click onto the link, it do help me open a new window. But the original page was "refresh", it kept go all the way back to the top. How can i resolve this problem?
code:
Response.Write("<script>window.open('" + url + "')</script>");
As I understand it, each time you click the link the page is being send to the server where the event is handled (with some C#). If you do that, the server will send the whole page back.
You probably want to control this on client side, with some Javascript.
That said, what you are problably looking for is the attribute target of the link:
something
That will tell the browser that you want to open another tab or windows when the user click the link, and then there request the page specified by url in that tab or window.
Sounds like you want Response.Redirect(myURL)
When you click on the link and handle it in the code behind, that means the link is run at the server side, so it has to post back, which makes it look like it's "refreshing", but it's actually posting back.
You need to handle the opening of the new window on the client's side via Javascript.
If your're writing this to your page, this will redirect you to the url you want
Response.Write("<script>;location.href='" + url + "'</script>");
I have a webservice and a default.aspx page in c#.
I want to perform a click of the link button on default page from the webservice.
How can i call the linkbutton of the default.aspx from the webservice?
Please suggest a genuine way for doing this.
Web services cannot "click" buttons. They can return data or perform certain process on their end; you in turn can hook into any callback function after the web service finishes processing to perform the click on your end.
Example:
$.ajax({
url: "URLTOWEBService.here",
success: function(){
//webservice returned successfully
performClick();
}
});
What does the button do? Instead of trying to click it remotely you should change architecture of your system to invoke logic under button via web service.
the closest you can get is if you return a javascript that "clicks" the button and is evaluated by the browser client.
The webservice itself can't do jack since its running on the server.