views:

1082

answers:

2

OK, I am not sure if the title it completely accurate, open to suggestions!

I am in the process of creating an ASP.NET custom control, this is something that is still relatively new to me, so please bear with me.

I am thinking about the event model. Since we are not using Web Controls there are no events being fired from buttons, rather I am manually calling __doPostBack with the appropriate arguments. However this can obviously mean that there are a lot of postbacks occuring when say, selecting options (which render differently when selected).

In time, I will need to make this more Ajax-y and responsive, so I will need to change the event binding to call local Javascript.

So, I was thinking I should be able to toggle the "mode" of the control, it can either use postback and handlle itself, or you can specify the Javascript function names to call instead of the doPostBack.

  • What are your thoughts on this?
  • Am I approaching the raising of the events from the control in the wrong way? (totally open to suggestions here!)
  • How would you approach a similar problem?

Edit - To Clarify

  • I am creating a custom rendered control (i.e. inherits from WebControl).
  • We are not using existnig Web Controls since we want complete control over the rendered output.
  • AFAIK the only way to get a server side event to occur from a custom rendered control is to call doPostBack from the rendered elements (please correct if wrong!).
  • ASP.NET MVC is not an option.
A: 

Very odd. You're using ASP.NET server controls and custom controls, but you're not using web controls? And you're calling __doPostBack manually?

Do you like to do things the hard way?

If I was still using the server control model rather than MVC, I would slap ASP.NET Ajax controls on that sucker and call it a day. What you're doing is like putting a blower on a model T. It may be fun and interesting, but after you're done with all the hard work, what do you really have?

Will
I would agree. Why are you recreating the wheel because MS has already done it for you. You are just spending more time writing code.
David Basarab
Question updated to clarify.
Rob Cooper
+1  A: 

I have been doing some more digging on this, and came across how to inject Javscript in to the client when required. This will obviously play a huge part in making the controls more responsive and lest round-trips to the server.

For example: RegisterClientScriptBlock.

Look forward to playing with this more, feel free to get invovled people!

Rob Cooper
What if you wrap your custom control in an ASP.NET AJAX UpdatePanel on the ASPX page?
AlexWalker