ASP.NET 2.0 TreeView control postback on checkChanged

J

japi

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
 
J

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$ContentPlaceHolder1$checkDoPostBack\',\'\')',
0);


}
 
Joined
Aug 26, 2007
Messages
1
Reaction score
0
Getting past the Inheritance problem

How did you get past the inheritance problem. ASPX files don't like multi-inheritance.


japi said:
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$ContentPlaceHolder1$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
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top