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

Accessing the AutoCompleteBoxItemData attributes client side

15 Answers 277 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Courtenay
Top achievements
Rank 1
Courtenay asked on 07 Feb 2013, 02:47 AM
Hi there,

Ive bound successfully to my web service and am returning the required data using the following:

foreach (Site site in sites)
 {
                AutoCompleteBoxItemData childNode = new AutoCompleteBoxItemData();
                childNode.Text = site.PublicName;
                childNode.Value = site.SiteId.ToString();
                childNode.Attributes.Add("PublicUrl", site.PublicUrl);
                childNode.Attributes.Add("Description", site.Description);
                result.Add(childNode);
}

How do I access though attributes (PublicUrl etc) client side in my OnClientEntryAdded method:

function onEntryCalendarAdded(sender, eventArgs)
 {
                debugger;
                var controlEntry = eventArgs.get_entry();
                // gain access to public url etc here
}

15 Answers, 1 is accepted

Sort by
0
Mike
Top achievements
Rank 1
answered on 21 Feb 2013, 03:41 PM
Hello,

Did you have any luck with this? I'm trying to do something similar binding a ClientDropDownItemTemplate and using an attribute and haven't had any luck...

Thanks,

Mike
0
Nencho
Telerik team
answered on 26 Feb 2013, 01:12 PM
Hello,

The attributes collection of entries is accessible at client-side. However, I am glad to inform you that we plan to introduce this functionality with our upcoming Service Pack.

All the best,
Nencho
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
Diana
Top achievements
Rank 1
answered on 10 Mar 2013, 02:43 PM
How can we access them client-side? I've tried every possible thing and nothing works. How can I get the attributes of a certain entry using JavaScript?
0
Nencho
Telerik team
answered on 12 Mar 2013, 01:18 PM
Hello,

The attributes collection of entries is Not accessible at client-side. Therefor we plan to introduce this functionality with the upcoming Service Pack. Please excuse me for my mistake.

Regards,
Nencho
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
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
answered on 13 May 2013, 12:47 PM
I am interested in the client-side attributes collection of the autocomplete box as a whole, not necessarily in individual entries... however I assume they go hand in hand. Any idea when we will be able to access the attributes client-side? Given that most of your controls have an attributes collection which is accessible client-side, I am surprised you would release a new control without this functionality.
0
Nencho
Telerik team
answered on 16 May 2013, 08:36 AM
Hello Albert,

The desired functionality is already logged as an improvement for the RadAutoCompleteBox. But, I am afraid that I cannot provide you with an exact timeframe for the release of this feature.

Kind regards,
Nencho
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
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
answered on 16 May 2013, 12:04 PM
I have to say that is quite troubling, Nencho. Since your post on March 12, where you said that this sort of functionality will be included in the next service pack there have been two service packs. And now you are saying you don't know when it will be included. In the past this sort of response from Telerik has typically meant it would be at least a year if not quite a bit longer for something to be done. If there's some sort of technical reason for a large delay, then I think we'd all appreciate an explanation. If not, then there really is no excuse. This functionality is not an "Improvement", its a complete oversight. As I mentioned previously, it should have been part of the initial release of the control, since it is native to the way just about every other Telerik control works.
0
Nencho
Telerik team
answered on 21 May 2013, 02:31 PM
Hello Albert,

The fix didn't make it to the first ServicePack we didn't have sufficient time and resources to implement it. The second ServicePack included only some Validation fixes, that were crucial for our users, and didn't contain any other control fixes of features.

Also, at the time of writing of the previous post it didn't seem feasible that we would have enough time to fit this fix into our schedule, and that's why we couldn't commit on the release date being the next major Q.

However since then we have re-examined the issue and we managed to resolve it, so it would be available in the 2013 Q2 release, which comes out in mid June.

Kind regards,
Nencho
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
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
answered on 21 May 2013, 03:25 PM
ok. thanks for the update.
0
Duncan
Top achievements
Rank 1
answered on 20 Aug 2013, 12:02 AM
So did this make it into the 2013 Q2 release?  If it did, how do we access the attributes client-side?  

Thanks!
0
Bozhidar
Telerik team
answered on 22 Aug 2013, 08:18 AM
Hello Duncan,

The feature did make it to the 2013 Q2 release, as stated in the release notes here:
http://www.telerik.com/products/aspnet-ajax/whats-new/release-history/q2-2013-version-2013-2-611.aspx

I've also attached a small sample page demonstrating how you can access the attributes on the client.
 

Regards,
Bozhidar
Telerik
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 the blog feed now.
0
Glen
Top achievements
Rank 1
answered on 09 Sep 2014, 05:34 PM
Is there a way to access the attributes when the input type is set to "Text" because I am getting an error when trying to retrieve an attribute using the sample code "alert(args.get_entry().get_attributes().getAttribute("attr"));"

I am getting a  JavaScript runtime error: Object doesn't support property or method 'get_entry' .... any thoughts would truly be appreciated.


Glen
0
Bozhidar
Telerik team
answered on 10 Sep 2014, 07:30 AM
Hello,

The OnClientTextChanged event event args contain only the get_text() function, as explained in our online documentation:
http://www.telerik.com/help/aspnet-ajax/autocompletebox-onclienttextchanged.html

This is because in text mode the AutoCompleteBox works in terms of pure text, rather than entries, which is why in text mode attributes are not supported.

Regards,
Bozhidar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
EJ
Top achievements
Rank 1
answered on 20 Mar 2020, 04:50 PM
I am unable to get the attributes using a web method to generate the data.  We want to use the attributes to populate other controls when the user selects an item from the drop down.  Is there anyway to get this data?
0
Peter Milchev
Telerik team
answered on 25 Mar 2020, 11:11 AM

Hello EJ,

Attached you can find a sample project where the attributes can be accessed properly when the AutoCompleteBox is bound to a web method.

<telerik:RadScriptManager ID="RadScriptManager1" EnablePageMethods="true" runat="server">
    <Scripts>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
    </Scripts>
</telerik:RadScriptManager>

<asp:Label Text="Label1" ID="Label1" runat="server" />

<telerik:RadAutoCompleteBox RenderMode="Lightweight" ID="RadAutoCompleteBox3" runat="server" Width="400" DropDownHeight="150" OnEntryAdded="RadAutoCompleteBox3_EntryAdded"
    EmptyMessage="Select Company Names">
    <WebServiceSettings Method="GetCompanyNames" Path="default.aspx" />
</telerik:RadAutoCompleteBox>

<telerik:RadButton RenderMode="Lightweight" runat="server" Text="Select" ID="Button3" OnClick="Button3_Click" />

protected void Button3_Click(object sender, EventArgs e)
{
    var attr = RadAutoCompleteBox3.Entries[0].Attributes["CustomAttribute"].ToString();
    Label1.Text = "Button click: " + attr;
}

protected void RadAutoCompleteBox3_EntryAdded(object sender, AutoCompleteEntryEventArgs e)
{
    var attr = e.Entry.Attributes["CustomAttribute"].ToString();
    Label1.Text = "EntryAdded: " + attr;
}

[WebMethod]
public static AutoCompleteBoxData GetCompanyNames(object context)
{
    string searchString = ((Dictionary<string, object>)context)["Text"].ToString();
    DataTable data = GetChildNodes(searchString);
    List<AutoCompleteBoxItemData> result = new List<AutoCompleteBoxItemData>();

    foreach (DataRow row in data.Rows)
    {
        AutoCompleteBoxItemData childNode = new AutoCompleteBoxItemData();
        childNode.Text = row["ProductName"].ToString();
        childNode.Value = row["ProductID"].ToString();
        childNode.Attributes.Add("CustomAttribute", "custom value#" + childNode.Value);
        result.Add(childNode);
    }

    AutoCompleteBoxData res = new AutoCompleteBoxData();
    res.Items = result.ToArray();

    return res;
}

private static DataTable GetChildNodes(string searchString)
{
    SqlCommand selectCommand = new SqlCommand(@"SELECT * FROM [Products] WHERE ProductName LIKE @ProductName + '%'");
    selectCommand.Parameters.AddWithValue("ProductName", searchString.Replace("%", "[%]").Replace("_", "[_]"));
    return GetData(selectCommand);
}

private static DataTable GetData(SqlCommand selectCommand)
{
    selectCommand.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
    SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);

    DataTable data = new DataTable();
    adapter.Fill(data);

    return data;
}

Regards,
Peter Milchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
AutoCompleteBox
Asked by
Courtenay
Top achievements
Rank 1
Answers by
Mike
Top achievements
Rank 1
Nencho
Telerik team
Diana
Top achievements
Rank 1
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Duncan
Top achievements
Rank 1
Bozhidar
Telerik team
Glen
Top achievements
Rank 1
EJ
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or