Whatever's inside the <%= %> gets run and becomes part of the HTML
that goes to the browser, so it will behave however it normally
would...
Suppose you have a textbox named txtLogin, but it renders as
ctl00_MyContentPlaceHolder_txtLogin (or whatever it looks like - I
forget exactly how they render).
Your aspx page has:
var textBox = document.getElementById("<%= txtLogin.ClientID %>");
It renders to the browser as:
var textBox = document.getElementById
("ctl00_MyContentPlaceHolder_txtLogin");
If you're talking about adding javascript events to asp.net controls,
I've seen that work, but I typically see that happen in code-behind -
for example, if you want to add an "onchange" to a textbox, you can
probably get away with:
<asp:TextBox id="txt1" runat="server" onchange="dosomething();" />
But it seems to be better practice to leave out the onchange in the
markup and instead go with the following in the code-behind:
txt1.Attributes.Add("onchange", "dosomething();");
You could always throw a runat attribute to a normal HTML element
instead of using the <asp:TextBox> style of tags, and then you can use
all of the normal javascript events straight on the markup - you won't
get all of the ASP.NET-specific stuff on that control, but if all you
need is a simple control, it will make absolutely no difference to the
rendered HTML.
<input id="txt1" runat="server" type="text" onchange="dosomething();" /
>
On Jan 5, 8:35 pm, "Brandon Betances" <[email protected]> wrote:
> And calling a function on an event of that control will work also?