Javascript and ASP tags

  • Thread starter Thread starter No One
  • Start date Start date
N

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?
 
Hi,

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.
 
Back
Top