0

I have seen a few other questions of a similar vein on here, but with no definitive answers.

I am looking for the best way to go about loading asp.net server controls (or user controls) from client script (likely jQuery). I am creating a small dashboard that will feature multiple controls/controls created as the result of client script call's and the controls will need to be able to run server side functions and are not just simple information display controls.

I have done something similar recently with loading details controls which were rendered via an HttpHandler from a jQuery $.get() and the resulting HTML of the control is injected into the DIV area - however these used a custom formless page as a temp placeholder as to not interfere with the current viewstate/rendering cycle on the page so they were only able to use HTML elements such as hyperlinks, etc.

This is different and I am looking for the best way to be able to load up controls which will act as if they were registered into the page at the beginning of the page life cycle because I want the controls to be able to run their own server side methods/events (some filtering, etc).

I have seen some people say you should really use UpdatePanel's for this and do the processing server-side - but I am loathe to do this as one of the requirements is heavily tied to using client script.

Yahel
  • 37,023
  • 22
  • 103
  • 153
watdo
  • 667
  • 8
  • 22
  • 3
    No matter what you do server side, you're *always* only able to use HTML elements. That's all that the browser *ever* sees. – Pointy Nov 27 '11 at 12:55

1 Answers1

0

I have experimented some with this and feel that ASP .Net stateful behaviour of the server side controls is really restricting when it comes to things like this.

If it is a simple dialog such as a login with username and password I can recommend that you do either a page method or a ashx handler that the javascript can communicate with, and then just build all the markup + server communication with your client side script.

But since you are building a more complex solution I would give you the advice that people already have suggested: Use UpdatePanels.

You can always hook up client scripts that run before the postBack (which shows the server side controls) is triggered, this client script can control if the postBack should fire or not etc. And you can also make the server side of the code invoke client side scripts when it have been rendered.

Things like this make you really appriciate ASP .Net MVC.

Community
  • 1
  • 1
Robin Andersson
  • 5,150
  • 3
  • 25
  • 44
  • I know, MVC is so much better at this kind of thing, but unfortunately I work on a legacy forms application. Thank you for the feedback much appreciated. – watdo Nov 27 '11 at 13:57