Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP.NET 2.0 TreeView control postback on checkChanged

Reply
Thread Tools

ASP.NET 2.0 TreeView control postback on checkChanged

 
 
japi
Guest
Posts: n/a
 
      09-13-2006
Hi all,

I have a TreeView control in my ASP.NET 2.0 Web application with
checkboxes enabled.

I would like to generate a postback when a user ticks or unticks a
checkbox. As far as i know, this is not possible out of the box.

Does anyone have a solution/workaround/hack for this?

Cheers,
Japi

 
Reply With Quote
 
 
 
 
japi
Guest
Posts: n/a
 
      09-13-2006
i fixed it myself.

1. made my own class that derives from the TreeView control.
2. implemented a override for Render method that adds a javascript
eventhandler to the checkboxes
3. added a dummy control whose postback call is called by the
checkboxes from my treeview

-------- code for overridden render method: --------

protected override void Render(HtmlTextWriter writer)
{
StringBuilder builder = new StringBuilder();

using(StringWriter stringWriter = new StringWriter(builder))
{
HtmlTextWriter tempWriter = new HtmlTextWriter(stringWriter);
base.Render(tempWriter);
}

string find = "<input type=\"checkbox\" ";
string replace = "<input type=\"checkbox\"
onClick=\"ReloadTreeView();\" ";

writer.Write(builder.ToString().Replace(find, replace));
}
------------ code for javascript function ---------

function ReloadTreeView(){
document.getElementById('ctl00_ContentPlaceHolder1 _checkDoPostBack').checked
= true;
setTimeout('__doPostBack(\'ctl00$ContentPlaceHolde r1$checkDoPostBack\',\'\')',
0);


}
japi wrote:
> Hi all,
>
> I have a TreeView control in my ASP.NET 2.0 Web application with
> checkboxes enabled.
>
> I would like to generate a postback when a user ticks or unticks a
> checkbox. As far as i know, this is not possible out of the box.
>
> Does anyone have a solution/workaround/hack for this?
>
> Cheers,
> Japi


 
Reply With Quote
 
 
 
 
jinksk jinksk is offline
Junior Member
Join Date: Aug 2007
Posts: 1
 
      08-26-2007
How did you get past the inheritance problem. ASPX files don't like multi-inheritance.


Quote:
Originally Posted by japi
i fixed it myself.

1. made my own class that derives from the TreeView control.
2. implemented a override for Render method that adds a javascript
eventhandler to the checkboxes
3. added a dummy control whose postback call is called by the
checkboxes from my treeview

-------- code for overridden render method: --------

protected override void Render(HtmlTextWriter writer)
{
StringBuilder builder = new StringBuilder();

using(StringWriter stringWriter = new StringWriter(builder))
{
HtmlTextWriter tempWriter = new HtmlTextWriter(stringWriter);
base.Render(tempWriter);
}

string find = "<input type=\"checkbox\" ";
string replace = "<input type=\"checkbox\"
onClick=\"ReloadTreeView();\" ";

writer.Write(builder.ToString().Replace(find, replace));
}
------------ code for javascript function ---------

function ReloadTreeView(){
document.getElementById('ctl00_ContentPlaceHolder1 _checkDoPostBack').checked
= true;
setTimeout('__doPostBack(\'ctl00$ContentPlaceHolde r1$checkDoPostBack\',\'\')',
0);


}
japi wrote:
> Hi all,
>
> I have a TreeView control in my ASP.NET 2.0 Web application with
> checkboxes enabled.
>
> I would like to generate a postback when a user ticks or unticks a
> checkbox. As far as i know, this is not possible out of the box.
>
> Does anyone have a solution/workaround/hack for this?
>
> Cheers,
> Japi
 
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
RadioButton CheckChanged event not firing on first selection Emma Middlebrook ASP .Net 0 04-23-2008 02:05 PM
CheckChanged inside my user control =?Utf-8?B?cm9kY2hhcg==?= ASP .Net 2 11-06-2007 07:17 PM
CheckChanged event not firing when unchecking CheckBox in GridView jlficken@gmail.com ASP .Net 1 07-12-2007 03:58 PM
CheckChanged is not the same as onclick Chris ASP .Net 0 04-21-2005 05:09 PM
CheckBox CheckChanged Event Jim Heavey ASP .Net 3 03-05-2004 06:54 PM



Advertisments