I have a masterpage in which i defined a function for getElementById
.
function Clear() {
document.getElementById('<%= NameTextBox.ClientID %>').value = "";
document.getElementById('<%= LastNameTextBox.ClientID %>').value = "";
}
when i use this function in other page it is clearing the element value.
but when i use this code in masterpage, i get error :
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
System.Web.UI.ControlCollection.Add(Control child) +9601391
AjaxControlToolkit.ScriptObjectBuilder.RegisterCssReferences(Control control) +691
AjaxControlToolkit.ScriptControlBase.OnLoad(EventArgs e) +44
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Control.LoadRecursive() +145
System.Web.UI.Control.LoadRecursive() +145
System.Web.UI.Control.LoadRecursive() +145
System.Web.UI.Control.LoadRecursive() +145
System.Web.UI.Control.LoadRecursive() +145
System.Web.UI.Control.LoadRecursive() +145
System.Web.UI.Control.LoadRecursive() +145
System.Web.UI.Control.LoadRecursive() +145
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
if i change my code to :
document.getElementById('<%# NameTextBox.ClientID %>').value = "";
i don't get error. but don't clear myelement.