Ajax en the Form_load event and Ajax in serveruser controls

G

Guest

Hello,
I want to understand teh benefits of ajax technology. Does anyone has a good
website where AJAX EXTENSIONS is worked out so I really understand it.

There a 2 main questions:
1) How about the form load event. Why should it fire when I put a button in
a update panel? Is this necessary and is only the other controls related to
the update panel send back? Or the whole page (If this is true I really do
not get it). But please answer me.
Is het neccesary to execute the form_load full, or is it possible to get
some more information (variables) which let you know to execute the Full
form_load or just a part.

2) I'm using usercontrols and within a user control I want to use ajax. But
my serverusercontrols uses CreateChildControls and all controls are loaded
during runtime. My code looks like:
Dim label1 As New Label
Label1.ID = ClientID + "L1"
Label1.Text = lblName
so all checkboxex hyperlinks, textboxes are dimension in the
CreateChildControls is it still possible to use AJAX?

Thanx

ton
 
B

Ben Rush

Hello Ton.

I should have an article coming out in MSDN (eventually) detailing many of
the things you are asking about, but for now I'll try to see if I can answer
them directly.

To answer your second question first, yes, you should be able to use your
control normally; there should be no differences to its lifetime or
construction on the server.

The form load event is necessary because the form must still be instantiated
on the server in order for the processing of ASP.NET to continue. There are
plenty of things that are required for controls to render, and a parent form
is one of them; hence the necessity to have the form be instantiated,
loaded, etc. just as it normally would. In your case of the button in the
UpdatePanel, if the Form_Load event never fired, then that would mean the
Form never responded to the Load event and is therefore not a part of the
control tree registered and running on the server for your ASP.NET
application - effectively the core infrastructure of ASP.NET would break
without a form hosting the server controls. The UpdatePanel is a child
control of the form, just as the button within the UpdatePanel is.

What controls are rendered on the server is a slightly more tricky question
to answer, but there is definitely a solid answer for it - in the standard
case any and all controls that are associated with an UpdatePanel will be
rendered, including (but not limited to) those that are inside the
UpdatePanel as child controls. Unless you are directly leveraging the core
scripting framework of ASP.NET AJAX (in which case you're responsible for
the response processing and therefore what gets returned to the client) you
will be dealing with UpdatePanels and their child controls.

Not all controls on the form will be rendered, therefore; only those that
are associated with the UpdatePanels on the page that are registered to
update due to the post-back event.

What's confusing you, at the core, is an understanding of what has changed
on the server. While it is true that one thing that has changed is WHAT gets
rendered, it's more accurate to understand the true difference is in HOW
something gets rendered. ASP.NET AJAX overrides the default rendering method
of the Form and therefore gets to be very selective about what controls (and
their associated child controls) are rendered. Using the standard HTTP
stream, the response from the child controls are emitted back to the client
in a specially formatted block of data that the client framework can parse
through and use to intelligently update the client content. The output
stream from all controls (starting at the UpdatePanel and working down) is
streamed back to the client where it updates the browser content via DHTML
operations.

There is more to it than this, and I've glossed over a few details for the
sake of simplicity over completeness; but I believe you get the basic idea.


--
~~~~~~~~~~~~~~~~~~~~~~~~~~
Ben Rush
Microsoft .NET Consultant
http://www.ben-rush.net/blog
http://www.sideshowsystems.com
 
G

Guest

thank you for your reply. I've experimented a bit but cat achieve what I want:

(this is still just a test, in my realworld project I want to use this kind
of code in a userserver control)

Here the example code in de page load event:
Dim updatepanel2 As New UpdatePanel
Dim but3 As New Button
Dim txt As New TextBox
updatepanel2.ID = "UP2"
txt.ID = "txt"
but3.Text = "ajax added"
but3.ID = "but3"
AddHandler but3.Click, AddressOf But3_Click
Panel2.Controls.Add(but3)
Panel2.Controls.Add(txt)
updatepanel2.ContentTemplateContainer.Controls.Add(Panel2)
Me.Controls.Add(updatepanel2)

The only existing control is the panel2, because I want to put it in a
certain place on my web form. If it is possible I would prefer to do this
even without a panel, but cant figure out (yet) how to use absolute
positioning in runtime added controls. (But thats another question.

When running this I get an error, telling tht I had to set the property of
the control to run at server? OK but how to do programmaticly.

thanx

ton
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top