Are User Controls Still Useful in our AJAXified World?

R

Robert Johnson

Using .NET 3.5...

Question: Is there an alternative to user controls that I can or should use
to identify and manage groups of related Web server controls? By "identify
and manage" I more specifically mean that I can have client-side logic that
causes (in the background) a related set of controls (+ associated styling
and client-side script) to be loaded into the current browser page.

Before AJAX (e.g., in the 1.1 days), a menu click in the browser would
trigger a standard PostBack. Server-side logic would then determine which
user control to load into a PlaceHolder control. The new page would then be
rendered back to the browser. I understand that with the UpdatePanel, we can
ajaxify this arrangement. But I don't want to use the UPdatePanel (payload
size + rendered markup + rendered tag ID issues, etc).

So I'm wondering if I should look to make use of ASP.NET User Controls as I
would have in the .NET 1.1 days, but somehow getting them to render to the
browser (without use of UpdatePanels)... OR is there some other, perhaps
more elegant, way to accomplish the intended effect but without making use
of user controls?

Thanks.
 
G

George

You are not being exactly clear at what you want to do and what is the
problem.

If you do not want to use UpdatePanel then it will be hard to use
UserControls the standard way since they depend on the life cycle of the
Page. Like Postback and ViewState functionality.

Since in AJAX type of application the visual portion (html) is generated
using javascript and server only supplies data teoretically you do not need
any visual control (like UserControls are)

But in reality you do not have complete application that is using AJAX
techology. Usually only some portion is AJAXified.
So it's always a mix with regular way and AJAX way.

If you want to AJAXify your application i would recomed using JQuery with
JTemplate
http://plugins.jquery.com/project/jTemplates to generate HTML from the data.


George.
 
R

Rain

You could use page web methods. These are static methods associated with the
page. The only problem is that they dont start a session as far as I know,
they can however be made to keep the session alive. So, in short, they are
'NOT' part of the page cycle, but they are however exceptionally fast !!!!!

If you can handle timed out session using them then this is an alternative.
 
G

George

You can use
<System.Web.Services.WebMethod(EnableSession=true)>
for WebMethods to be able to use session

George
 
R

Robert Johnson

Thanks for the feedback George...

RE:
The OP was triggered more by my interests in the design of a new app that
I'm building rather than solving a specific technical/implementation
problem.

Prior to AJAX being part of my skill set I was approaching this app from a
"1.1 world view" where I was encapsulating [UI controls + associated
code-behind logic]. Then, at runtime, I would swap out user controls during
a standard PostBack. The intent was and still is to present only one [UI
controls + associated code-behind logic] to the user at a time - letting the
user effectively chose which one by selecting from a menu.

But now that I'm finally getting into the "AJAX mindset" I was wondering how
I might ajaxify the above scenario in an elegant way - with "elegant way"
meaning that the solution (1) minimizes network traffic; (2) performs faster
rather than slower for an ajax solution; and (3) doesn't result in an
enormous amount of junk cluttering the rendered page. These 3 objectives,
IMO, mean that UpdatePanels are not going to be something I will use.

Consequently I was wondering how I would go about delivering the solution.
Are user controls still a reasonable way to "package" the [UI controls +
associated code-behind logic]? The UI controls in question here are
relatively sophisticated controls that are part of a 3rd party component
suite... so it's not like I'm simply wanting to add rows to a table and make
parts of a page slide into/out of view. The [UI controls + associated
code-behind logic] deliver relatively sophisticated functionality to the
user. These UI controls, themselves, have the ability to communicate to
server-side logic via AJAX/JSON, so I'm not terribly concerned about
sessions, ViewState, and form submission.. My question here is about the
possible role of ASP.NET user controls in this scenario. Are they the
mechanism I should be using to "package" related groups of UI controls?

Thanks.
 
G

George

Robert Johnson said:
Thanks for the feedback George...

RE:
The OP was triggered more by my interests in the design of a new app that
I'm building rather than solving a specific technical/implementation
problem.

Prior to AJAX being part of my skill set I was approaching this app from a
"1.1 world view" where I was encapsulating [UI controls + associated
code-behind logic]. Then, at runtime, I would swap out user controls
during a standard PostBack. The intent was and still is to present only
one [UI controls + associated code-behind logic] to the user at a time -
letting the user effectively chose which one by selecting from a menu.

But now that I'm finally getting into the "AJAX mindset" I was wondering
how I might ajaxify the above scenario in an elegant way - with "elegant
way" meaning that the solution (1) minimizes network traffic; (2) performs
faster rather than slower for an ajax solution; and (3) doesn't result in
an enormous amount of junk cluttering the rendered page. These 3
objectives, IMO, mean that UpdatePanels are not going to be something I
will use.

Consequently I was wondering how I would go about delivering the solution.
Are user controls still a reasonable way to "package" the [UI controls +
associated code-behind logic]? The UI controls in question here are
relatively sophisticated controls that are part of a 3rd party component
suite... so it's not like I'm simply wanting to add rows to a table and
make parts of a page slide into/out of view. The [UI controls + associated
code-behind logic] deliver relatively sophisticated functionality to the
user. These UI controls, themselves, have the ability to communicate to
server-side logic via AJAX/JSON, so I'm not terribly concerned about
sessions, ViewState, and form submission.. My question here is about the
possible role of ASP.NET user controls in this scenario. Are they the
mechanism I should be using to "package" related groups of UI controls?

Thanks.


I would say yes... In my development I am still heavily using UserControls
with AJAX.
UserControls are great to separate parts of the web page into more
manageable components.

With AJAX you have 2 options.

1. The Fastest, but the hardest. Send data from the server and let
Javascript generate HTML. With this approach your applications is very
similar to the WebService.

2. The slowest but more easy to implement. Generate HTML on the server and
send it over to the browser and let Javascript to paste it into appropriate
place.
This is how UpdatePanel work and because it's universal it's simply allows
the whole page to be rendered and then cuts out the only HTML that is
included between <UpdatePanel> tags and send it to the browser.

You cold have develop something and not use UpdatePanel and using
UserControl.RenderControl(TextWriter wr) to generate HTML only for this user
control and send it to browser but then some functionality will be lost.
Like PostBacks will stop functioning for example....Or if you work more then
you might make postbacks work but something else will not work. At the end
you might end up with custom UpdatePanel object :)
So it's up to you.... where to stop.


George.



George.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top