I think its' all to do with the INamingContainer that it belongs to inferring a
name for it. Someone else suggested predictablenames which sounds like what you
want.
On 5 Jan 2012, at 02:14, Greg Keogh wrote:
> >Havent' done ASP.Net for a while but could you try do it later than you are
> >- pre_render or something.
>
> You’re right !!! Page_Load is too early ... well ... I suppose it is, but the
> symptoms of getting mismatching ClientIDs is quite frightening and
> misleading. I moved the register script call to before base.OnPreRender in
> the vague hope that the IDs would be “stable” by them.
>
> At the same time I changed my code. Instead of smartly enabling the save
> button as the text changes, I dumbly block save on click if the text is
> empty. This is not as elegant, but still acceptable for live use. The old
> code had a bug where the state of the button was incorrect when the page
> first loaded and I couldn’t figure out how to fire the script on load to set
> the initial state correctly, that wasted another 30 minutes. The working code
> now looks like this:
>
> Page.ClientScript.RegisterStartupScript(GetType(), "s3",
> string.Format(@"function CheckNote()
> {{
> var text = document.getElementById('{0}');
> if (text.value == '')
> {{
> alert('You cannot save a blank message.');
> return false;
> }}
> else
> {{
> return true;
> }}
> }}", textNote.ClientID), true);
> btnConSave.Attributes["onClick"] = "return CheckNote();";
>
> I also found that using <%=textNote.ClientID%> does not work in the get.
>
> So there you go, I’ve spent 2 and a half hours this morning trying to make
> this work. Why does it have to be so hard?
>
> Greg