Javascript code to do callback with itemIndex

4 posts, 1 answers
  1. Paul
    Paul avatar
    55 posts
    Member since:
    Nov 2010

    Posted 11 Jun 2012 Link to this post

    I would like to use the XmlHttpPanel to display some content and I am trying to minimise server load.

    I have a set of imagebuttons within a repeater control. Its the first time I've used the XmlHttpPanel. The XmlHttpPanel displays information from a specific database record defined by InfoId. I can set the repeater datasource with information containing InfoId. I could set the commandArgument for the buttons to  '<%# Eval("InfoId") %>' but that would then involve a postback to execute an OnCommand event. I therefore assume that it would be more efficient (a little like the First Look example in the demos) to have the imagebutton OnClientClick execute a javascript function that then sets the XmlHttpPanel value to the correct InfoId and the panel can then get the required information.

    I have two questions: (1) am I write that dealing with the button click in javascript rather than a command postback would be more efficient and (2) that being the case can someone help me with how to set the OnClientClick property of the imagebutton in the repeater. I keep getting messages that the tag isn't well formed or some other error.

    I'm assuming that the following javascript is fine (and it works if I hard code the OnClientClick property for a button):

    <
    script type="text/javascript">

     function myClientClick(index)

     {
    var myControl = $find("<%= myXmlHttpPanel.ClientID %>");

     

    myControl.set_value(index);

    return false;

    }
    </script>


    However, to make this work I need the OnClientClick property to be of the form: "return OnAdditionalSelect('x')" where x is the InfoId. If I use Eval("InfoId") I get errors and putting \' to try to get the single quotes around the id also causes a "tag not well formed" error.

     

  2. Answer
    Slav
    Admin
    Slav avatar
    1355 posts

    Posted 13 Jun 2012 Link to this post

    Hi Paul,

    Indeed, the RadXmlHttpPanel will deliver much better performance compared to UpdatePanel or RadAjaxPanel when no viewstate and control lifecycle execution is required. I have prepared a sample that demonstrates the logic which you want to implement. Please use it as a reference for incorporating the desired feature into your actual project.

    All the best,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paul
    Paul avatar
    55 posts
    Member since:
    Nov 2010

    Posted 13 Jun 2012 Link to this post

    Hi Slav, Thank you for your reply and for the clarification about the performance. Since my post I've been using the xmlhttppanel and its a great control. I've got a couple of specific questions:

    I have an array of buttons that are associated with my xmlhttppanel. In some ways its a bit like the first look demo on your website where you have a drop down list the drives the contents for the XmlHttpPanel. Is there any good/bad/best/worst way to structure this. Is it best for the buttons/comboBox.... to be outside the XmlHttpPanel or should they be inside?

    My second question is more generic and not specifically about the rad controls. In your sample (thank you) you have 'LoadData(<%# Eval("Id") %>); return false;'. I was trying to do: "return OnAdditionalSelect('x')".  The problem that I get is that if Id is numeric just doing Eval("Id") returns the number but the code requires single quotes around it (ie '3', or '123'). Trying to solve this I just get "tag not well formed" or other error (depending on what I try).
  5. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 18 Jun 2012 Link to this post

    Hi Paul,

    It is recommended to put the controls that initiates the request to the server outside the RadXmlHttpPanel and to add inside only the content received from the web service or the callback. You can check the Getting Started help article to learn more about the way RadXmlHttpPanel works.

    As for the The server tag is not well formed error, you should wrap the handler method, specified in the event property, in single quotes if there are double quotes used inside. If you are having problems determining the exact cause, please send a sample of your markup so that I can locate it and suggest a solution. Also, you can still pass an integer to the function and convert it to a string in order to format it as needed.

    All the best,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top