Add reset to defaults button to asp form but avoid postback
I have a couple of fields on a form that will be populated with default values. I would like to put a button that will allow me to reset those fields to their default values if they have been modified. However I would like to avoid the postback so that I don't have data being sent to the database.
Is it possible to add a javascript hook such that when that button is pressed I can pull the default values and populate those fields开发者_JAVA技巧 in javascript?
yes. if that's all the button does you can use a standard html button.
<input type="button" value="reset" onclick="restoreDefaults();">
and in javascript
function restoreDefaults() {
var myTextBox1 = document.getElementById('<% =myServerControlTextBox.ClientID %>');
myTextBox1.value = 'my default value';
}
精彩评论