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

Load on demand using webservice issue

1 Answer 70 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Samir
Top achievements
Rank 1
Samir asked on 28 Oct 2010, 05:52 PM
Hi
  I am using webservice to return items similar to demo. I need to have radio buttons in the items that postbacks. So i am dynamically creating radiobuttonlist and listitems in the getrotatoritems function in the webservice and since item can only return pure client html, i am using htmltextwriter to render the radiobuttonlist into string and attaching that to item.Html property. The issue i am having is htmltextwriter is loosing the autopostback property of the radiobuttonlist, so even though i am setting autopostback = true, its not posting back. Did i miss anything?? Or is there any workaround for this?

thanks
-Samir

1 Answer, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 03 Nov 2010, 09:48 AM
Hello Samir,

I have already answered your support ticket. For convenience I have pasted my reply here as well:

"The problem that you experience is not directly related to RadRotator control. The issue is caused by the fact that the RadioButton's properties are not rendered by the RenderControl method. You can manually add some attributes, however, by using the ListItem's Attributes property.
Private Function GetRadioButtonList() As String
    Dim radioList As New RadioButtonList()
    radioList.ID = "RadioButtonList1"
 
    Dim item1 As New ListItem("Item1", "Item1")
    Dim item2 As New ListItem("Item2", "Item2")
    Dim item3 As New ListItem("Item3", "Item3")
 
    item1.Attributes.Add("onclick", "onRadioClickHandler(this);")
    item2.Attributes.Add("onclick", "onRadioClickHandler(this);")
    item2.Attributes.Add("onclick", "onRadioClickHandler(this);")
 
    radioList.Items.Add(item1)
    radioList.Items.Add(item2)
    radioList.Items.Add(item3)
 
    Dim sw As New StringWriter()
    Dim writer As New HtmlTextWriter(sw)
    radioList.RenderControl(writer)
    writer.Flush()
 
    Return sw.ToString()
End Function

Then you can assign the returned HTML by the GetRadioButtonList method to the RadRotatorItemData.Html property:
Private maxItemsCount As Integer = 3
Private itemCount As Integer = 1
 
<WebMethod> _
Public Function GetRotatorData(itemIndex As Integer) As RadRotatorItemData()
    If itemIndex >= maxItemsCount Then
        Return Nothing
    End If
    Dim result As New List(Of RadRotatorItemData)()
 
    For i As Integer = itemIndex To itemIndex + (itemCount - 1)
        Dim item As New RadRotatorItemData()
        item.Html = Me.GetRadioButtonList()
        result.Add(item)
    Next
 
    Return result.ToArray()
End Function


The 
onRadioClickHandler JavaScript handler should be declared on the page which hosts the RadRotator control:

<head runat="server">
    <style type="text/css">
         
    </style>
    <script type="text/javascript">
 
        function onRadioClickHandler(clickedButton)
        {
            alert(clickedButton.checked);
 
            // Use AjaxPanel to call server-side method
        }
    </script>
</head>
<body class="BODY">
    <form id="Form1" method="post" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadRotator ID="RadRotator1" runat="server" Width="100" ItemWidth="100"Height="100"
        ItemHeight="100">
        <WebServiceSettings Path="RotatorWebService.asmx" Method="GetRotatorData"/>
    </telerik:RadRotator>
    </form>
</body>
</html>
"

Best wishes,
Fiko
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Rotator
Asked by
Samir
Top achievements
Rank 1
Answers by
Fiko
Telerik team
Share this question
or