The postback of several actions to control the TreeView in IE WebControl alone

Source: Internet
Author: User
treeview|web| control in the use of this TreeView is often required to postback the action to the server to do some data operations, such as onexpanded or Selectindexchange. The TreeView control provides a AutoPostBack property to set whether the TreeView needs to perform postback action to get the background to manipulate the data. But once this property is set to True, all the actions of the TreeView will postback back to refresh the page, either expaned or Selectindexchangek postback back. Most of the time we just need to postback some of these things back. If all events are postback, it will not only affect the user experience but also affect system performance. The way to solve this problem is to deal with the postback of each action, if the conditions are not postback, as far as possible to reduce unnecessary postback.

Here's an example of how to control postback's movements.

protected Microsoft.Web.UI.WebControls.TreeView Tvschema;

private void Page_Load (object sender, System.EventArgs e)

{


if (! IsPostback)
{
To modify the code for expand client Events
string script = @ "javascript:if (this.clickednodeindex!= null) {
This.queueevent (' Onexpand ', this.clickednodeindex);
Expandedtable (This,this.clickednodeindex);
}
";
tvschema.attributes["Onexpand"]=script;
}
Registering Control scripts

Registetreescript ();

}

private void Registetreescript ()

{

String script

= @ "<script language= ' JavaScript ' >

function expandedtable (sender,_nodeindex)

{



var node=sender.gettreenode (_nodeindex);



Postback if there is no child object;

if (Node.getchildren (). length==0)

"+getpostbackeventreference (Tvschema) +@";

}

</script> ";

This. RegisterClientScriptBlock ("Tvschema", script);

}

private void Tvschema_expand (object sender, Microsoft.Web.UI.WebControls.TreeViewClickEventArgs e)

{

Build the subtree yourself according to the selected target

}

In the code above, most of the registetreescript () functions are client script, but these client scripts cannot trigger the postback of the page, so you need to call GetPostBackEventReference (Tvschema To generate a postback script, but this function is not just a return to __doPostBack (' Tvschema ', '), the string is so simple. When there is no other postback action on your page WebControl, he automatically generates that __doPostBack client script.





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.