Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brad 2 posts 22 karma points
    Jul 01, 2013 @ 14:29
    Brad
    0

    Calling a function in a user control to set an attribute in the code behind

    I am currently trying to build a user control with a form. The form contains an asp:textbox element which has a custom attribute called data-source which I would like to set from a function in the code behind. The reason I need to use that attribute name is because I am using a premade autocomplete box which requires this name as the attribute name.

    I have tried things like:

            <asp:TextBox ID="categories" ClientIdMode="static"  runat="server" data-provide="typeahead" data-items="4" data-source="<%=categoryList() %>"></asp:TextBox>

    ....

    data-source="<%#categoryList() %>
    ....
    I have also tried several ways to insert the attribute into the ascx page from the ascx.cs page. I have tried to set the categories.data-source = categoryList(); (i have seen this in some online tutorials but this does not work). I have also tried to use AddAttribute in the Page_Load function but this does not seem to work for me either.
    Does anyone have any ideas on what I can try in order to get the return string from the categoryList function to automatically complete the data-source attribute.
    (Sorry for the basic question but I am a beginner at umbraco and c# .net.)

  • Stefan Kip 1606 posts 4098 karma points c-trib
    Jul 01, 2013 @ 15:02
    Stefan Kip
    0

    As long a the method categoryList() is returning a string, this should work (in you page_load method):

    categories.Attributes.Add("data-source", categoryList());
    

     

  • Brad 2 posts 22 karma points
    Jul 02, 2013 @ 10:09
    Brad
    0

    Thanks - Works perfectly.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies