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

Page Method instead of Web Service

2 Answers 112 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
SamVanity
Top achievements
Rank 2
SamVanity asked on 19 Feb 2009, 12:38 AM
Is there a way we can use page method instead of web service? If so, what are the steps involved to make this happen?

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Feb 2009, 06:51 AM
Hi Sam Van,

I have tried using PageMethods in order to populate RadComboBox. See the example.

ASPX:
<telerik:RadComboBox ID="RadComboBox1" runat="server" ToolTip="Please enter your title" Skin="WebBlue" EnableLoadOnDemand="True" AutoPostBack="True" > 
</telerik:RadComboBox> 
<input id="Button1" onclick="LoadItems();" type="button" value="GetItems" /> 

JavaScript:
<script type="text/javascript">  
function LoadItems()  
{  
    PageMethods.GetItems(onGetComplete);                  
}  
function onGetComplete(result)   
{  
    var data = result;  
    srcArray = new Array(10);  
    srcArray = data;  
    for(var i=0;i<data.length;i++)  
    {  
        AddNewItem(data[i]);  
    }             
}  
function AddNewItem(data)  
{  
    var combo = $find("RadComboBox1");  
    combo.set_closeDropDownOnBlur(false);  
    var intextput = data;  
    var comboItem = new Telerik.Web.UI.RadComboBoxItem();  
    comboItem.set_text(intextput);  
    combo.trackChanges();  
    combo.get_items().add(comboItem);  
    comboItem.select();  
    combo.commitChanges();  
    comboItem.scrollIntoView();      
}  
</script> 

C#:
using System.Web.Services;  
public partial class PageMethod : System.Web.UI.Page  
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
    }  
    [WebMethod]  
    public static string[] GetItems()  
    {  
        string[] items = { "Item1""Item2""Item3" };  
        return items;  
    }     

Thanks,
Princy.
0
SamVanity
Top achievements
Rank 2
answered on 19 Feb 2009, 12:48 PM
thanks for your reply, but I was referring to the feature that when you type something into the box, the box requests a pagemethod instead of a web service.

But your code is certainly useful (client side API). I am thinking maybe we can handle the OnClientItemsRequesting event: issue set_cancel(true) + call the page method in this handler. Then use your code to add items to the combo box...
Tags
ComboBox
Asked by
SamVanity
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
SamVanity
Top achievements
Rank 2
Share this question
or