0

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?

ryokan
  • 125
  • 2
  • 12
  • Take a look at [Page.RegisterClientScriptBlock](https://msdn.microsoft.com/en-us/library/system.web.ui.page.registerclientscriptblock(v=vs.110).aspx) and [ClientScriptManager.RegisterClientScriptBlock](https://msdn.microsoft.com/en-us/library/btf44dc9(v=vs.110).aspx) I think one of these might be helpful to you. – Jason Evans Nov 03 '15 at 10:09

1 Answers1

0

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.

Community
  • 1
  • 1
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • So I need calls server side like: Page.ClientScript.RegisterStartupScript(this.GetType(), "keyName", script, true); And then send the elements in the JavaScript call? – ryokan Nov 03 '15 at 10:12
  • That code will put the code in the HTML, so you just need to call this from your server side code. – Patrick Hofman Nov 03 '15 at 10:13