按钮onclick事件未触发...当onclientclick返回true时 [英] button onclick event not firing...when onclientclick returns true
问题描述
大家好,我在asp.net中有一个按钮如下
hello everyone, i have a button in asp.net as follows
<asp:Button ID="btnNext" runat="server" Height="26px" OnClientClick="return CheckIfOptionSelected();" OnClick="btnNext_Click" Text="Next"
Width="77px" />
i已对单选按钮进行了一些验证,如果在单选按钮中没有选择任何内容然后它返回false ...因此服务器端事件不会触发。这工作正常,但是,我有一个jquery计时器...并根据要求...在计时器过去后我想提交表格...或导致onclick无论发生什么......所以我'写了以下内容
i have done some validation to radio buttons, if nothing is selected in the radio buttons then it returns false...hence the server side event does not fire. This works fine, however, i have a jquery timer...and according to the requirement...after the timer elapse i want to submit the form...or cause the onclick to fire no matter what...so i''ve written the following
function CheckIfOptionSelected() {
var radioButton1 = document.forms[0].elements['ctl00_MainContent_rdBtnListOptions_0'];
var radioButton2 = document.forms[0].elements['ctl00_MainContent_rdBtnListOptions_1'];
var radioButton3 = document.forms[0].elements['ctl00_MainContent_rdBtnListOptions_2'];
var radioButton4 = document.forms[0].elements['ctl00_MainContent_rdBtnListOptions_3'];
if (radioButton1.checked != true && radioButton2.checked != true && radioButton3.checked != true && radioButton4.checked != true && countdownCurrent != 0) {
return false;
}
else {
countdownReset();
return true;
}
}
function countdownReset() {
var newCount = parseInt($('#ctl00_MainContent_example2submit').val()) * 100;
if (newCount > 0) { countdownCurrent = newCount; }
}
现在这也可以正常工作......但只有在radiobuttonlist中没有选择任何内容时......但是,如果我选择一个项目...并让计时器过去......在这种情况下,onclick不会触发。我不知道问题是什么?... FYI-当计时器过去时,jquery导致下一步按钮点击它自己。
jquery我正在使用...
now this works fine as well...but only when nothing is selected in the radiobuttonlist...however ,if i select an item...and let the timer elapse...in this case the onclick does not fire. I don''t know what the issue is?...FYI- the jquery causes the "Next" button to Click itself when the timer elapse.
the jquery i''m using...
var countdownTimer, countdownCurrent;
$(document).ready(function () {
countdownCurrent = $('#ctl00_MainContent_example2submit').val() * 100;
countdownTimer = $.timer(function () {
var min = parseInt(countdownCurrent / 6000);
var sec = parseInt(countdownCurrent / 100) - (min * 60);
var micro = pad(countdownCurrent - (sec * 100) - (min * 6000), 2);
var output = "00"; if (min > 0) { output = pad(min, 2); }
$('.countdowntime').html(output + ":" + pad(sec, 2) + ":" + micro);
if (countdownCurrent == 0) {
var btn = document.getElementById('<%=btnNext.ClientID%>');
btn.click();
} else {
countdownCurrent -= 7;
if (countdownCurrent < 0) { countdownCurrent = 0; }
}
}, 70, true);
$('#example2submit').bind('keyup', function (e) { if (e.keyCode == 13) { countdownReset(); } });
});
我注意到的另一件事是生成的HTML包含onclick =return CheckIfOptionSelected( );...
another thing i noticed is that the generated HTML contains onclick="return CheckIfOptionSelected();"...
<div class="ctrlStyle1">
<span id="ctl00_MainContent_btnNext$ajaxdest" name="__ajaxmark"><input type="submit" name="ctl00$MainContent$btnNext" value="Next" onclick="return CheckIfOptionSelected();" id="ctl00_MainContent_btnNext" style="height:26px;width:77px;" /></span>
<span id="ctl00_MainContent_btnSubmit$ajaxdest" name="__ajaxmark"></span>
</div>
推荐答案
(' #ctl00_MainContent_example2submit ')。val())* 100 ;
if (newCount> 0 ){countdownCurrent = newCount; }
}
('#ctl00_MainContent_example2submit').val()) * 100; if (newCount > 0) { countdownCurrent = newCount; } }
现在这也可以正常工作......但只有在radiobuttonlist中没有选择任何内容时......但是,如果我选择一个项目...并让计时器过去......在这种情况下,onclick不会触发。我不知道问题是什么?... FYI-当计时器过去时,jquery导致下一步按钮点击它自己。
jquery我正在使用...
now this works fine as well...but only when nothing is selected in the radiobuttonlist...however ,if i select an item...and let the timer elapse...in this case the onclick does not fire. I don''t know what the issue is?...FYI- the jquery causes the "Next" button to Click itself when the timer elapse.
the jquery i''m using...
var countdownTimer, countdownCurrent;
( document )。ready( function (){
countdownCurrent =
(document).ready(function () { countdownCurrent =
(' #ctl00_MainContent_example2submit')。val()* 100 ;
countdownTimer =
('#ctl00_MainContent_example2submit').val() * 100; countdownTimer =
这篇关于按钮onclick事件未触发...当onclientclick返回true时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!