CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2005
    Posts
    33

    TreeView checkboxes AutoPostBack with AJAX

    Hello,

    There is a known problem with TreeView checkboxes in ASP.NET: they can't do AutoPostBack. So I've solved this problem like this:

    <script language="javascript" type="text/javascript">

    function postbackOnCheck()
    {
    var o = window.event.srcElement;
    if (o.tagName == 'INPUT' && o.type == 'checkbox' &&
    o.name != null && o.name.indexOf('CheckBox') > -1)
    {
    __doPostBack("","");
    }
    }

    </script>

    <asp:TreeView onclick="postbackOnCheck()" ID="treeContent"
    runat="server"> ... And so on ... </TreeView> This way I get full postback each time the user checks\unchecks the checkbox.

    But now I want to modify this code in order to make use of AJAX: I don't want the FULL postback, but I only want the tree itself to be updated. Of course, I've started by placing it inside the UpdatePanel. But what now? Can somebody help me with this issue?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: TreeView checkboxes AutoPostBack with AJAX

    AJAX does a wonderful job of altering the innerHTML content of DIV tags. Why don't you just re-write that content with the new treeview?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Apr 2005
    Posts
    33

    Re: TreeView checkboxes AutoPostBack with AJAX

    Quote Originally Posted by PeejAvery
    AJAX does a wonderful job of altering the innerHTML content of DIV tags. Why don't you just re-write that content with the new treeview?
    Hmmm... Can you please give me an example?

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: TreeView checkboxes AutoPostBack with AJAX

    It's the most basic form of AJAX. Take a look here.

    Code:
    <div id="theDIV"><div>
    
    <script language="JavaScript">
      var theDIV = document.getElementById('theDIV');
      theDIV.innerHTML = "This will be the DIV's content.";
    </script>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Apr 2005
    Posts
    33

    Re: TreeView checkboxes AutoPostBack with AJAX

    No, that won't work for me... There has to be a postback, because my tree is dynamic, it is filled in "lazy" mode on server-side. So I can't check the checkboxes on the client-side - they may not exist there at all...

    Do you know how can I update the update panel on the client-side? I know that there is some way using PageRequestManager... But I can't find how exactly this works. This is the only thing I need to solve the issue now...

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: TreeView checkboxes AutoPostBack with AJAX

    Quote Originally Posted by Dmitry Perets
    Do you know how can I update the update panel on the client-side?
    That is exactly what I am trying to show you. AJAX sends data to the server and then sends the data back to the client-side. Did you even browse into the link I posted? There are more pages there to browse. Read the whole AJAX section.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured