how can i add client side javascript to a web user control?

  • Thread starter Thread starter Tariq Ahmad
  • Start date Start date
T

Tariq Ahmad

hi,

i have a web user control that i wish to add some client-side
javascript to. something like this: onChange="javascript:DoSomething();"

how can i add this and where do i need to add it? do i need to somehow
add it to my .ascx file?

i tried to add it into my HTML like below but it does not
get rendered when i do View|Source.

<uc1:TypeAheadComboBox id="cboPaymentTerm"
onChange="javascript:DoSomething();" runat="server"></uc1:TypeAheadComboBox>

i also tried to add it to my .ascx file like below but this gives errors:

Protected bdBody As HtmlGenericControl
Public Sub New()
bdBody.Attributes("onChange") = "window.alert('changed');"
End Sub

any advice appreciated.

thanks.
 
works a charm ... thanks a lot!

(note for anyone else wanting to do this:
your control must expose its Attributes collection. if it doesnt
u will still be able to do Attributes.Add but it will not work as
desired).
 

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

Back
Top