ASP.NET 2.0 TreeView control postback on checkChanged

Discussion in 'ASP .Net' started by japi, Sep 13, 2006.

  1. japi

    japi Guest

    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
     
    japi, Sep 13, 2006
    #1
    1. Advertising

  2. japi

    japi Guest

    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
     
    japi, Sep 13, 2006
    #2
    1. Advertising

  3. japi

    jinksk

    Joined:
    Aug 26, 2007
    Messages:
    1
    Getting past the Inheritance problem

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


     
    jinksk, Aug 26, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Heavey

    CheckBox CheckChanged Event

    Jim Heavey, Mar 5, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    6,579
    Jim Heavey
    Mar 5, 2004
  2. Chris
    Replies:
    0
    Views:
    479
    Chris
    Apr 21, 2005
  3. Replies:
    1
    Views:
    1,061
    nahid
    Jul 12, 2007
  4. =?Utf-8?B?cm9kY2hhcg==?=

    CheckChanged inside my user control

    =?Utf-8?B?cm9kY2hhcg==?=, Nov 6, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    319
    =?Utf-8?B?cm9kY2hhcg==?=
    Nov 6, 2007
  5. Emma Middlebrook
    Replies:
    0
    Views:
    569
    Emma Middlebrook
    Apr 23, 2008
Loading...

Share This Page