开发者

Webforms: Enable Submit button after confirmation code entered

开发者 https://www.devze.com 2023-01-17 20:35 出处:网络
I am working on an WebForms app, and we want to put a speed bump, for lack of a better term, in for the users at a particular point in the app. There is a particular action which is not supposed to be

I am working on an WebForms app, and we want to put a speed bump, for lack of a better term, in for the users at a particular point in the app. There is a particular action which is not supposed to be undone. So when they click the button to do that action we want to display a small confirmation window, have them enter a random string that we give them. Once they enter that string, and it matches the corresponding label, 开发者_开发百科the submit button becomes enablesand they can perform the action. But for the life of me I can't figure out a good way to do this client side with WebForms. Is there a simple mechanism to use this type of workflow without a ton of post back events?

Note: This is an internal app where high security isn't truly a necessary requirement in this case. As I said, this is meant to be something to slow the user down slightly.


This is similar to the mint.com confimration style.

Add JavaScript to the textbox onChange or onKeyUp event, there do your check and enable the button.

For example:

<script type="text/javascript">
function checkConfirmationText(){
 // Check if value of entered text = value of hidden text
 var isOk = document.getElementById('confirmation-label').value == document.getElementById('confirmation-text').value);

 // Show/Hide button depending on the text
 document.getElementById('btn-submit').style.dispaly = isOk ? '' : 'none';
}
</script>

<!--  HTML  -->
<input type="hidden" id="confirmation-label" value="DELETE" />
Enter "DELETE": <input type="text" id="confirmation-text" value="" onkeyup="checkConfirmationText()" />
<input type="submit" id="btn-submit" style="display:none" />


You could generate the javascript method to check the code (including the code in the method) server side and use registerclientscriptblock (or whatever the current method is), then use the onblur to call that method.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号