Reputation: 57
I've created a table of dynamic controls which each row is a couple of (DropDownList and TextBox) then I've associated an event handler on each DropDownList selected change event so I can change on its TextBox as the code below shows :
DropDownList TypeDDL = new DropDownList();
TypeDDL.ID = "TypeDDL_" + rowN.ToString();
TypeDDL.Width = 120;
TypeDDL.Height = 20;
InitializeTypeDDL(TypeDDL);
TypeDDL.AutoPostBack = true;
TypeDDL.Attributes.Add("onchange", "javascript:handleFieldsDDLEvent(this);");
TextBox FieldsDDL = new TextBox();
FieldsDDL.ID = "FieldsDDL_" + rowN.ToString();
FieldsDDL.Width = 120;
FieldsDDL.Height = 20;
FieldsDDL.Attributes.Add("style", "float:right");
but the Javascript code of the event handler fires an exceptions telling:
function handleFieldsDDLEvent(e) {
var elementId = (e.target || e.srcElement).id;
var IdArray = elementId.Split('_');
var ControlId = "Control_"+IdArray[1].toString();
if (IdArray[1] != "") {
var FieldsDDL = document.getElementById("<%="+ControlId +".ClientID%>");
// error CS1026: ) expected
ValueTxtBx.style.display = "none";
}
}
Upvotes: 0
Views: 2040
Reputation: 83709
In your javascript you have
var FieldsDDL = document.getElementById("<%="+ControlId +".ClientID%>");
The <%= ... %>
parts are rendered on the server so it cannot be done this way in javascript.
Upvotes: 3