How Server Render works during Asp.net Ajax 1.0 asynchronous callback

Source: Internet
Author: User
When Asp.net Ajax 1.0 asynchronous callback, the principle of server-side render is first reviewed.
Page Lifecycle

Preinit
Init
Initcomplete
Loadstate
Processpostdata
Preload
Load
Loadcomplete
Prerender
Preparecallback // If callback exists
Prerendercomplete
Savestate
Savestatecomplete
Render

Both Asp.net requests and Ajax requests must execute the previous page lifecycle,

At the end of the page, page. rendercontrol () is called to display all the child controls of the page.

The procedure is as follows:

Page. rendercontrol
Control. rendercontrol ()
Control. rendercontrol (writer, this. adapter)
Control. rendercontrolinternal ()
Control. Render () // at this time, page. Render () will overwrite it
Control. renderchildren ()
Control. rendercontrolinternal ()

Now the key
Control. rendercontrolinternal () is implemented as follows:
If it is not Asp.net Ajax processing, it will certainly execute foreach to traverse all the child controls in turn

Internal void renderchildreninternal (htmltextwriter writer, icollection children)
{
// Normally, if rarefields is not set, the default process is followed to process all child controls,
// If rarefields is set, renderchildren is rewritten in a custom way.
If (this. rarefields! = NULL) & (this. rarefields. rendermethod! = NULL) // when you setrendermethoddelegate, rarefieldsensured has a value.
{
Writer. beginrender ();

// Call the rendermethod delegate. When Asp.net ajax1.0 uses control. setrendermethoddelegate, the corresponding callback function is processed at this time.
This. rarefields. rendermethod (writer, this );
Writer. endrender ();
}
Else if (children! = NULL)
{
// If this rarefieldsensured is not set, all the controls in the page will be rendered
// Call the rendercontrol of all sub-controls in the control
Foreach (Control in children)
{
Control. rendercontrol (writer );
}
}

}

The above is Asp.net's render Processing
Someone must ask what the above if is. This is the Microsoft stream interface. The entire Asp.net Ajax relies on this interface for processing.

In ASP. netajax1.0, you must put a scriptmanager.
It is also a subclass of control,
In onprerender of the page lifecycle, it calls

Pagerequestmanager. onprerender ();

The problem is that pagerequestmanager. onprerender () is implemented as follows:

_ Owner. ipage. setrendermethoddelegate (renderpagecallback );

What is the setrendermethoddelegate () method used?

In control, when you call setrendermethoddelegate, it sets the value for control. rarefieldsensured.
Public void setrendermethoddelegate (rendermethod)
{
// Use occasionalfields. rarefield
This. rarefieldsensured. rendermethod = rendermethod;
This. Controls. setcollectionreadonly ("collection_readonly_codeblocks ");
}

All of this is clear. When you set renderpagecallback, the normal Asp.net process will no longer go, and all the child controls will not be render
Used in ASP. netajajax 1.0

Private void renderpagecallback (htmltextwriter writer, control pagecontrol)
{
...
// Retrieve the current htmlform
Ihtmlform formcontrol = _ owner. ipage. form;

// Manually set the callback method when formcontrol. rendercontrol () is enabled, because subcontrols in page. controls will not be render.
// Manually process a ticket
Formcontrol. setrendermethoddelegate (renderformcallback );

// Similarly, htmlform. rendercontrol will not be automatically triggered in page. Controls
// At this time, you need to manually renderctronl to call renderformcallback.
Formcontrol. rendercontrol (formwriter );

// Generate client callback information | asyncpostbackcontrolids
Encodestring (writer, asyncpostbackcontrolidstoken, String. Empty, getasyncpostbackcontrolids (false ));
// Generate client callback information | postbackcontrolids
Encodestring (writer, postbackcontroliden, String. Empty, getpostbackcontrolids (false ));
// Generate client callback information | updatepanelids | tupdatepanel
Encodestring (writer, updatepanelidstoken, String. Empty, getallupdatepanelids ());
// Generate client callback information | childupdatepanelids
Encodestring (writer, childupdatepanelidstoken, String. Empty, getchildupdatepanelids ());
// Generate client callback information | panelstorefreshids
Encodestring (writer, updatepanelstorefreshtoken, String. Empty, getrefreshingupdatepanelids ());
// Generate client callback information | asyncpostbacktimeout
Encodestring (writer, asyncpostbacktimeouttoken, String. Empty, _ owner. asyncpostbacktimeout. tostring (cultureinfo. invariantculture ));

........

}

Private void renderformcallback (htmltextwriter writer, control containercontrol)
{
....
// Present all updatepanel
If (_ updatepanelstorefresh! = NULL)
{
Foreach (updatepanel panel in _ updatepanelstorefresh)
{
If (panel. Visible)
{
Panel. rendercontrol (_ updatepanelwriter );
// What client callback information will be generated
/// 169 | updatepanel | updatepanel1 |/R/n
}
}

}
...
// Sequentially write the rendercontrol of all controls on the page into dummywriter
Foreach (Control in containercontrol. Controls)
{
Control. rendercontrol (dummywriter );
// Generate part of the information
<Input type =/"Submit/" name =/"button1/" value =/"button/" id =/"button1/"/>/R/n
<Input name =/"TXT/" type =/"text/" value =/"wxy/" id =/"TXT/"/>/R/n
}

Note: During renderformcallback, httprequest will manually flush () to add the above information to IIS
}

For ctronl. Render, how does one write htmltextwriter and then httpwriter,
Write it back to httpworkrequest, and finally refresh it back to the kernel, or use socket to send it back to the server, which is not covered in this article .......

As can be seen from the above, Asp.net Ajax does not use the traditional httprequest. Filter to process sending back information, but uses the built-in Asp.net 2.0 method and callback

Asp.net Ajax callback is rendered to the client in two parts, one of which is generated by renderformcallback as follows:

The following client script is generated in renderformcallback.
169 | updatepanel | updatepanel1 |/R/n
 
<Input type =/"Submit/" name =/"button1/" value =/"button/" id =/"button1/"/>/R/n
<Input name =/"TXT/" type =/"text/" value =/"wxy/" id =/"TXT/"/>/R/n

Part of the Code is generated by renderpagecallback.

52 | hiddenfield
|__ Viewstate |/wepdwujnjg1nja3ndcxzgrcx32ah2i/NEQ + gcfrvr49kqdecw = | 56
| Hiddenfield |__ eventvalidation |/wewawkf344xaoznisygapkgsmijofjkiskpyp0o2nxupnjna29hmla = | 0
| Asyncpostbackcontrolids | 0 | postbackcontrolids | 13 | updatepanelids | tupdatepanel1 | 0
| Childupdatepanelids | 12 | panelstorefreshids | updatepanel1 | 2 | asyncpostbacktimeout | 90 | 12
| Formaction | default. aspx | 13 | pagetitle | untitled page |

In the client part, SYS. webform. _ onformsubmitcompleted () encapsulates all information in JSON type: type, ID: ID, content: content
Obtain updatepanel and set its innerhtml. For details about the client, see Zhao's blogs.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.