Javascript and ASP tags


No One

I have a few ASP.Net tag generated controls that need to have client run
Javascript assigned to the click method. When I try to assign a
Javascript function call to the OnClick property of the control, I get a
run time error when it tries to render the page. Can Javascript be
added to ASP.Net tag generated controls, or do I have to replace these
with the standard old HTML tags?

Ken Dopierala Jr.


You need to do this in your code behind by adding an Attribute to your
server control. For example:

Protected WithEvents btnSend As System.Web.UI.WebControls.Button

Public Sub Page_Load()
btnSend.Attributes.Add("onclick", "ButtonClick();")
End Sub

ButtonClick() is the javascript function in your HTML that will be run when
the button is clicked. Good luck! Ken.

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