Call Javascript Function
-
How do you call a javascript function when a button is clicked? I know you can use the OnClick event, but that will fire up everytime the button is clicked. I need to call the function only when certain criteria are met. For example private void btnSave_Click(object sender, System.EventArgs e) { if (flag == true) { //Call Javascript function } } Thanks.
-
How do you call a javascript function when a button is clicked? I know you can use the OnClick event, but that will fire up everytime the button is clicked. I need to call the function only when certain criteria are met. For example private void btnSave_Click(object sender, System.EventArgs e) { if (flag == true) { //Call Javascript function } } Thanks.
You can't call a javascript function from the server, all you can do is rerender the page and insert script that calls it. Is flag calculated based on client side state ? If so, use a custom validator. If it isn't, then just insert client side variables that have these values, so you can validate them on the client, and still avoid a postback.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
How do you call a javascript function when a button is clicked? I know you can use the OnClick event, but that will fire up everytime the button is clicked. I need to call the function only when certain criteria are met. For example private void btnSave_Click(object sender, System.EventArgs e) { if (flag == true) { //Call Javascript function } } Thanks.
adding onto what chris wa saying you can check out my article here which helps explain things a bit more http://www.codeproject.com/useritems/JavascriptValidation.asp
Kind Regards, Gary
My Website || My Blog || My Articles
-
How do you call a javascript function when a button is clicked? I know you can use the OnClick event, but that will fire up everytime the button is clicked. I need to call the function only when certain criteria are met. For example private void btnSave_Click(object sender, System.EventArgs e) { if (flag == true) { //Call Javascript function } } Thanks.