Folks, I just returned to a web app to make some changes after several weeks
of leaving it untouched. Of course it now crashes in some JavaScript where
there has never been a problem before. I just want to disable a Save button
when a text box is empty, so I do this in Page_Load:
textNote.Attributes["onFocus"] = "NoteCheck();";
textNote.Attributes["onKeyUp"] = "NoteCheck();";
Page.ClientScript.RegisterClientScriptBlock(GetType(), "S1",
string.Format(@"function NoteCheck()
{{
var text = document.getElementById('{0}');
var btn = document.getElementById('{1}');
var len = text.value.length;
btn.disabled = (len == 0);
}}", textNote.ClientID, btnConSave.ClientID),
true);
The controls textNote and btnConSave are inside a content holder inside a
repeater inside a grid, which is a bit messy, but despite this the code used
to work. Now both getGelementById calls are returning null and the debugger
stops on the "len =" line.
I can see in the page source that all of the generated (quite long) ClientID
values are correct and it all seems to match-up. How on earth can the IDs
not be found? Is there a better way of doing this?
Greg