问题
i have a infragistics web grid which has row edit template. Row edit template contains drop down list. Now when i change the selected index of drop down.. i need to get the client id of the drop down.. the web grid is in Content place holder..
i am using the below code..
ctl00_ContentPlaceHolder1_webModGrid_ctl00_ddlScope
but it is giving error..
Microsoft JScript runtime error: Object required
回答1:
you can try to use the switch 'ClientIDMode' and its value Static
http://msdn.microsoft.com/en-us/library/system.web.ui.clientidmode.aspx
回答2:
It is possible to evaluate the ClientID property of the required control (and its client-side tag object) in the following manner:
var clientID = '<%=ddlScope.ClientID%>';
var element = document.getElementById(clientID);
if (element) {
}
Otherwise, if the DropDownList is placed into the INamingContainer, it is possible to render the corresponding client-side object from the page’s code behind by handling the control’s Init event and using the ClientScript.RegisterStartupScript method in the following manner:
<asp:DropDownList ID="ddlScope" runat="server" OnInit="ddlScope_Init">
</asp:DropDownList>
protected void ddlScope_Init(object sender, EventArgs e) {
DropDownList ddl = (DropDownList)sender;
string script = string.Format("var _{0} = document.getElementById('{1}');", ddl.ID, ddl.ClientID);
Page.ClientScript.RegisterStartupScript(Page.GetType(), "ANY_KEY", script, true);
}
var element = _ddlScope;
alert(element);
Does it make a sense?
来源:https://stackoverflow.com/questions/5364426/infragistics-get-clientid-of-dropdown-in-rowedit-template