Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > [Solution] Treeview without Autopostback but with SelectedIndexChange

Reply
Thread Tools

[Solution] Treeview without Autopostback but with SelectedIndexChange

 
 
Stefan
Guest
Posts: n/a
 
      07-18-2003
Hi,

I developed an ASP.NET Web Application with many User Controls in it. One of
that including
the MS Treeview Control. Since i wanted the Control to track the
SelectedIndex, i implemented
a server-side eventhandler to do so.

One of the drawbacks of the Treeview Control (as others mentioned too) is
its Autopostback-
functionality (On: Postback on all events including expanding of nodes and
so on / Off: All Postbacks
off). So i searched the web for a solution, to let the Treeview Control fire
the postback only in case of
SelectedIndexChange event but not in other cases. (relevant performance
costs)

The Solution posted by Patrick Cole (Microsoft Developer Support) was
perfectly matching but
could only be used in applications implementing the TreeView Control in
Webpages (but not in
User Controls) because of the need to modify the <body> tag.

Here this Solution:
http://groups.google.com/groups?hl=e...tngxa08&rnum=6

I modified this solution in such way, that it can be used "everywhere" (i
tested it only in my user control), here
the code:

================================================== ====
public abstract class TheUserControl : System.Web.UI.WebControl
{
protected Microsoft.Web.UI.WebControls.TreeView ctlTree;

private void Page_Load(object sender, System.EventArgs e)
{
Page.RegisterClientScriptBlock("TreeEvent",
this.BuildClientsideEventhandler());
this.ctlProjectTree.Attributes.Add("onselectedinde xchange",
"javascript:treeEvent();");
}

private String BuildClientsideEventhandler()
{
String nl = Environment.NewLine;
String strRef = Page.GetPostBackEventReference(ctlTree);
String strControl = this.ctlProjectTree.UniqueID.Replace(":", "_");
return "<script language=\"JavaScript\">" + nl +
"<!-- " + nl +
" function treeEvent() {" + nl +
" if (event.oldTreeNodeIndex != event.newTreeNodeIndex) " + nl +
" " + strControl + ".queueEvent('onselectedindexchange',
event.oldTreeNodeIndex + ',' + event.newTreeNodeIndex); " + nl +
" window.setTimeout('" + strRef.Replace("'","\\'") + "', 0,
'JavaScript'); " + nl +
" } " + nl +
"// --> " + nl +
"</script>";
}
}
================================================== =========

You don't have to do anything additionaly..

Sincerlely,
Stefan Kals
(E-Mail Removed)
http://www.css-web.net


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IEWC:Treeview, automatically check subnodes without AutoPostBack Tronex ASP .Net Web Controls 2 02-24-2005 10:42 PM
Help - Treeview - SelectedIndexChange Event Phil ASP .Net Web Controls 0 04-29-2004 04:15 PM
Dropdownlist SelectedIndexChange is firing twice!! Jay ASP .Net 1 03-04-2004 05:08 AM
SelectedIndexChange Ruby ASP .Net 0 01-21-2004 10:31 AM
treeview SelectedIndexChange problem steven shingler ASP .Net Web Controls 2 07-28-2003 01:36 PM



Advertisments