function Button1_onclick() {
}
vb code -
Button1.Attributes.Add("onclick", "Button1_onclick()")
need a varible from vb code to be passed to button1_onclick()
I'm assuming "VB code" is code behind code, and the Button1_onclick() function is client-side JavaScript. If that is the case, to pass a server-side variable to the method, you only have to send the value with the event handler like this:
Button1.Attributes.Add("onclick", "Button1_onclick('" + var.ToString() + "')")
Now your JavaScript function should look like the following:
function Button1_onclick(serverValue) {
//whatever
}
Remember that the new JavaScript onclick handler with the variable will be updated only the the page goes back to the server, which is when you server-side VB code is run anyways. There's no "live" connection between the server and client code.
This was first published in August 2003