I'm currently working on a project using the Ajax Tabs control in ASP.NET. My language for this project is VB.NET. I'm trying to take advantage of the "OnClientClick" event on the tabs. I'm populating the tabs using data from a database, and I'm using a VB Function to actually create the tabs. The VB code is as follows:
Protected Sub makeTab(ByVal categoryName As String, ByVal categoryId As String)
Dim label As New Label
label.Text = categoryName
Dim tab As New AjaxControlToolkit.TabPanel
tab.Controls.Add(label)
tab.HeaderText = categoryName
tab.OnClientClick = "display_alert(" + categoryId + ")"
tcResultSet.Tabs.Add(tab)
'Next
For x As Integer = 1 To tcResultSet.Tabs.Count
If tcResultSet.Tabs(tcResultSet.Tabs.Count - x).HeaderText = "Tab0" Then tcResultSet.Tabs.RemoveAt(tcResultSet.Tabs.Count - x)
Next
End Sub
This function is called for every record that the database returns.
In the ASPX page, the tab container is:
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePartialRendering="true" />
<asp:TabContainer ID="tcResultSet" runat="server" AutoPostBack="true" ScrollBars="auto" >
<asp:TabPanel ID="tbTab0" runat="server" HeaderText="Tab0" />
</asp:TabContainer>
and my javascript function is:
<script type="text/javascript" >
function display_alert(categoryNumber) {
window.alert("Hello! You clicked a tab");
}
</script>
and it is placed inside of my page head at the top of the page. As you can see, I'm currently not even using my variable inside my Javascript function, but I will. Currently, this code does not work. It works if I remove the variable from the Javascript function definition, and if I call my Javascript function (from my VB) like "display_alert". It will not work if I include "()" after the function name. Is there any way around this? Any way to make this work properly?