By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,369 Members | 1,188 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,369 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.


Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You can do it that way:
cboPaymentTerm.Attributes.Add("onchange", "DoSomething();")

"Tariq Ahmad" <ta*********@hotmail.com> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
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.


Nov 17 '05 #2

P: n/a


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).

"Anatoly" <an******@gilat.com> wrote in message
news:Og**************@TK2MSFTNGP11.phx.gbl...
You can do it that way:
cboPaymentTerm.Attributes.Add("onchange", "DoSomething();")

"Tariq Ahmad" <ta*********@hotmail.com> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
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.



Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.