This is a migrated thread and some comments may be shown as answers.

Javascript code to do callback with itemIndex

3 Answers 84 Views
XmlHttpPanel
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 11 Jun 2012, 10:31 AM

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.

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Slav
Telerik team
answered on 13 Jun 2012, 01:40 PM
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.
0
Paul
Top achievements
Rank 1
answered on 13 Jun 2012, 06:52 PM
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).
0
Slav
Telerik team
answered on 18 Jun 2012, 07:26 AM
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.
Tags
XmlHttpPanel
Asked by
Paul
Top achievements
Rank 1
Answers by
Slav
Telerik team
Paul
Top achievements
Rank 1
Share this question
or