Hi Peter,
From your description, I understand that you are using Tab Control and you
want to find every control in this Tab Container using JavaScript. If I
have misunderstood you, please feel free to let me know.
ASP.NET doesn't have built-in Tab Control. So could you please tell us
which Tab Control you are using? In this case, I assume that you are using
ASP.NET Ajax Tab Container, and the following example is basing on ASP.NET
Ajax Tab Container.
To disable control in client, we need to get object of the control and
then
set its corresponding property using JavaScript. But how can we get them
from Tab Container? The answer is that we can loop all controls in Tab
control and then set property.
We can also use document.getElementById method with control's ClientID as
parameter to get this control. To do so, we can save the ClientID of the
control in Hidden Field, and then use JavaScript to retrieve ClientID from
this Hidden Field and set its property.
Note: The ClientID value is generated for a control is identical to the
UniqueID by ASP.NET and is used to programmatically access the HTML
element
rendered for a control in client-side script. For more information about
ClientID, see
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx
For the simple example, we place a HiddenField control in the ASP.NET page
and save control's ClientID in this HiddenField's value from CodeBehind
class, and then we access HiddenField's value in JavaScript:
==========================
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
HiddenField1.Value += TextBox1.ClientID +"$";
HiddenField1.Value += TextBox2.ClientID + "$";
}
}
</script>
<html xmlns="
http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function DisableControl()
{
var obj = document.getElementById('HiddenField1');
var idArray = obj.value.split('$');
for ( var i=0; i< idArray.length; i++)
{
if(idArray
!= '')
{
var control = document.getElementById(idArray);
control.disabled = true;
}
}
}
function EnableControl()
{
///
///TO DO: Enable control
///
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:scriptmanager ID="ScriptManager1" runat="server">
</asp:scriptmanager>
<AjaxToolkit:tabcontainer ID="TabContainer1" runat="server"
ActiveTabIndex="0">
<ajaxtoolkit:tabpanel ID="TabPanel1" runat="server"
HeaderText="TabPanel1">
<contenttemplate>
<input id="btnDisableAnthoerTabControl" type="button"
value="Disable another controls"onclick="DisableControl();" />
</contenttemplate>
</ajaxtoolkit:tabpanel>
<ajaxtoolkit:tabpanel ID="TabPanel2" runat="server"
HeaderText="TabPanel2">
<contenttemplate>
<asp:textbox ID="TextBox1"
runat="server"></asp:textbox>
</contenttemplate>
</ajaxtoolkit:tabpanel>
<ajaxtoolkit:tabpanel ID="TabPanel3" runat="server"
HeaderText="TabPanel3">
<contenttemplate>
<asp:textbox ID="TextBox2"
runat="server"></asp:textbox>
</contenttemplate>
</ajaxtoolkit:tabpanel>
</AjaxToolkit:tabcontainer>
<asp:hiddenfield ID="HiddenField1" runat="server" />
</form>
</body>
</html>
=================================
Note: If there is UserControl, we can also refer to this HiddenField and
then add control's id to it.
For example, in UserControl's CodeBehind class:
//HiddenField1 is in the parent page
HiddenField hf = (HiddenField)Page.FindControl("HiddenField1");
hf.Value += TextBox1.ClientID + "$";
I look forward to receiving your test results.
Best Regards,
Thomas Sun
Microsoft Online Partner Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
With newsgroups, MSDN subscribers enjoy unlimited, free support as opposed
to the limited number of phone-based technical support incidents. Complex
issues or server-down situations are not recommended for the newsgroups.
Issues of this nature are best handled working with a Microsoft Support
Engineer using one of your phone-based incidents.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.