Attribute not found in javascript from code behind

5 posts, 0 answers
  1. Ramin
    Ramin avatar
    9 posts
    Member since:
    Mar 2012

    Posted 11 Oct 2012 Link to this post

    I have created and added tabs in code behind, yet the javascript on tab selected does not show the attribute.

    Here is my code:
                var tabPanel = new RadTabStrip();
                tabPanel.OnClientTabSelected = "onTabSelected";
                var newTab = new RadTab() {Text = "All", Selected = true};
                newTab.Attributes["type"] =  "0";
                tabPanel.Tabs.Add(newTab);
     
    ....
    ....
                foreach (var department in deparmentsDt)
                {
                    var newTab = new RadTab() {Text = department.strDepartmentGroup_Name};
                    newTab.Attributes["type"] = department.intDepartmentGroup_ID.ToString();
                    tabPanel.Tabs.Add(newTab);
                }


    And then my javascript is simply:
    function onTabSelected(sender, args) {
        var tab = args.get_tab();
        var attr = tab.get_attributes();
        alert(attr.get_count()+" - " +attr.getAttribute("type") + " - " + tab.get_text());
    }


    count is always 0 and getattribute is always undefined.

    Any help would be appreciated.

    Thanks
    Loren 
  2. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 16 Oct 2012 Link to this post

    Hi Loren,

    Using the line below does not actually create an attribute to the Tab but rather provide an access to an existing one:
    newTab.Attributes["type"] =  "0";

    In order to create a custom attribute for the Tab I would suggest that you use the following code:
    var tabPanel = new RadTabStrip();
           //tabPanel.OnClientTabSelected = "onTabSelected";
           tabPanel.OnClientTabSelecting = "onTabSelecting";
           var newTab = new RadTab() { Text = "All", Selected = false };
           newTab.Attributes.Add("CustomAttribute", "0");
           tabPanel.Tabs.Add(newTab);
           form1.Controls.Add(tabPanel);

    Regards,
    Kate
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ramin
    Ramin avatar
    9 posts
    Member since:
    Mar 2012

    Posted 16 Oct 2012 Link to this post

    Hi Kate,

    I tried that and it still doesnt work.  BTW, both methods create the same markup - which is below:

    <LI class="rtsLI rtsFirst" _itemTypeName="Telerik.Web.UI.RadTab"><A class=rtsLink href="#" type=0><SPAN class=rtsOut><SPAN class=rtsIn><SPAN class=rtsTxt>All</SPAN></SPAN></SPAN></A></LI>


    However, in the javascript, attributes collection seems to be 0 :(

    Any help would be appreciated. Thanks!

    Loren
  5. Ramin
    Ramin avatar
    9 posts
    Member since:
    Mar 2012

    Posted 16 Oct 2012 Link to this post

    Looks like I resolved the problem.  There are apparently certain words you cant use as your key for attributes.  You should make that known.  Apparently, "type", "id", "class", "style" do not work.  What others?  I changed it to "customAttribute" and that worked!  Its not exactly descriptive of what I want, but it will do for now.
  6. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 17 Oct 2012 Link to this post

    Hi Loren,

    Since our controls inherit WebControls there are certain words that can not be used as names of the custom attributes. Therefore I would suggest that you use either prefix or suffix like CustomType, for instance and use it instead.   

    All the best,
    Kate
    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017