Reputation: 9416
I have a .ascx ComboBoxControl defined as below. Lets call it Control1
<%@ Control Language="C#" AutoEventWireup="true"
Inherits="ComboBoxControl" Codebehind="ComboBoxControl.ascx.cs" %>
<table border="0" cellpadding="0" cellspacing="0" style="border: 0px solid red">
<tr>
<td style="width: 60px; vertical-align: top">
<asp:TextBox ID="txtSelectedMLValues" class="dropdownbox" runat="server" ReadOnly="true" Style="width: 60px;" EnableViewState="true" Font-Size="11px" />
</td>
<td style="width:14px;" class="imgalign" align="left">
<img alt="" id="imgShowHide" runat="server" src="~/Images/drop.gif" height="20" />
</td>
</tr>
<tr>
<td class="DropDownLook" style="vertical-align: top" colspan="2">
<div style="vertical-align: top;">
<div id="divCheckBoxListClose" runat="server" class="DivClose" style="font-weight:700;color:Black; font-size:11;padding-left:6px;">
<label id="lblClose" runat="server" class="LabelClose Green" >
Click Here To Close <span class="closecross" style="vertical-align:text-bottom; margin-bottom:-1px; " >X</span></label>
</div>
<div id="divCheckBoxList" runat="server" class="DivCheckBoxList">
<div>
<asp:CheckBox ID="chkAll" runat="server" CssClass="CheckBoxList leftPaddingforcombo" Text="ALL" ToolTip="ALL"/>
</div>
<asp:CheckBoxList ID="chkMultipleValues" runat="server" CssClass="CheckBoxList"
Width="500px" >
</asp:CheckBoxList>
</div>
</div>
</td>
</tr>
</table>
In the controls code behind .cs file, i have below code that sets the ComboBoxControl's onClick event.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtSelectedMLValues.Attributes.Add("onclick", "ShowMList(" + divCheckBoxList.ClientID + "," + divCheckBoxListClose.ClientID + ")");
chkMultipleValues.Attributes.Add("onblur", "HideMList(" + divCheckBoxList.ClientID + "," + divCheckBoxListClose.ClientID + ")");
chkMultipleValues.Attributes.Add("onclick", "FindSelectedItems(this," + txtSelectedMLValues.ClientID + "," + chkAll.ClientID + ");");
}
}
I'm using the above ComboBoxControl (Control1) in another .ascx control (Lets call it Control2) like below.
<td width="15px" style="text-align: left;display: inline-block;">
<uc2:ComboBoxControl ID="ComboBoxControlNames" runat="server" />
</td>
The problem i'm having is that when i select a checkbox in the ComboBoxControl, i get the following error "ctl00_ContentPlaceHolderMain_ctl00_ComboBoxControlNames_txtSelectedMLValues' is undefined"
Note that "ContentPlaceHolderMain" is an asp:ContentPlaceHolder in my MasterPage.
When i view the page source, ClientID "ctl00_ContentPlaceHolderMain_ctl00_ComboBoxControlNames_txtSelectedMLValues" is there but IE 11 is throwing an error that it is undefined.
In chrome, the error doesn't appear. I'm struggling with how to stop that error in IE 11.
Upvotes: 0
Views: 601
Reputation: 207501
The code will render as
<input onclick="ShowMList( theOneId, theOtherId)" />
As you can see they will be seen as variables and not strings. You need to wrap them in quotes.
txtSelectedMLValues.Attributes.Add("onclick", "ShowMList('" + divCheckBoxList.ClientID + "','" + divCheckBoxListClose.ClientID + "')");
now do that for the others
Upvotes: 1