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

Attribute not found in javascript from code behind

4 Answers 81 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Ramin
Top achievements
Rank 1
Ramin asked on 11 Oct 2012, 10:54 PM
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 

4 Answers, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 16 Oct 2012, 01:27 PM
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.
0
Ramin
Top achievements
Rank 1
answered on 16 Oct 2012, 03:40 PM
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
0
Ramin
Top achievements
Rank 1
answered on 16 Oct 2012, 04:15 PM
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.
0
Kate
Telerik team
answered on 17 Oct 2012, 03:15 PM
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.
Tags
TabStrip
Asked by
Ramin
Top achievements
Rank 1
Answers by
Kate
Telerik team
Ramin
Top achievements
Rank 1
Share this question
or