running javascript function on a webcontrol

H

hemant

hi all,
i am working on a website using asp.net-vb.net
i am using a textbox(web control) and want to run javascript function
as the text in the textbox is changed. but as soon as i run the page
in the browser i get the foll. message:

Compiler Error Message: BC30456: 'func' is not a member of
'ASP.frmMaster_aspx'.
where func is name of the function


<asp:textbox id="txtDetails" runat="server"
OnTextChanged="func()"></asp:textbox>

i have gone thro' the problem and have found that being a web control
the compiler finds it a problem, that which function is to be run
while executing the code. the function asp.net provides in its
framework or the one i have written in the script and that's why it
gives the error.

now there is a perfect syntax which is to be used at the code-behind
at the pageload. i have tried a few but was unsuccessful. please tell
me what is to be written in the HTML of teh page and at the
codebehind(vb.net)


please help.
 
K

Ken Cox [Microsoft MVP]

You have to do this using the *client-side* event, not the server-side
event. So, in your user control, use the following:

Private Sub Page_Load _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
TextBox1.Attributes.Add("onchange", "alert('changed');")
End Sub

When you add this to the .aspx page it will render like this:

<input name="Txtusr1:TextBox1" type="text" id="Txtusr1_TextBox1"
onchange="alert('changed');" />

Ken
Microsoft MVP [ASP.NET]
Toronto
 
G

Guest

Another solution is to use client control, instead of server control:
<input type="text" onchange="func();">

Hope this helps!
Regards,
Kostadin Kostov
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top