C# 使用javascript取消所有事件
我有一个asp链接C# 使用javascript取消所有事件,c#,javascript,asp.net,C#,Javascript,Asp.net,我有一个asp链接 <asp:LinkButton ID="next" CssClass="Button Large" runat="server" OnClick="Next_Click" OnClientClick="showBillingRequiredState(this)">Next</asp:LinkButton> 下一步 当它被点击时,我想从continue中取消页面,如果我的javascript返回false,我希望它只是取消处理。现在我显示了一个错误
<asp:LinkButton ID="next" CssClass="Button Large" runat="server" OnClick="Next_Click" OnClientClick="showBillingRequiredState(this)">Next</asp:LinkButton>
下一步
当它被点击时,我想从continue中取消页面,如果我的javascript返回false,我希望它只是取消处理。现在我显示了一个错误,但是错误消失了,并且它没有坚持。。有东西导致它刷新,我丢失了我的错误。这里是javascript,正如我提到的,它可以很好地通过我的所有条件,并显示div,但过了一秒钟它就消失了
function showrequired(evt) {
var code = document.getElementById('<%=codelist.ClientID%>').options[document.getElementById('<%=codelist.ClientID%>').selectedIndex].value;
var currentValue= document.getElementById('<%=statevalue.ClientID%>').value;
var eDiv = document.getElementById('reqDiv');
if (code == "US" && currentValue.trim() == '') {
eDiv.style.display = 'block';
return false;
}
else {
eDiv.style.display = 'none';
}
}
需要显示功能(evt){
var code=document.getElementById(“”)。选项[document.getElementById(“”)。selectedIndex]。值;
var currentValue=document.getElementById(“”).value;
var eDiv=document.getElementById('reqDiv');
如果(代码==“US”&¤tValue.trim()=”){
eDiv.style.display='block';
返回false;
}
否则{
eDiv.style.display='none';
}
}
jquery事件默认值在这种情况下非常有效
<script>
$("#<%= next.ClientID %>").click(function(event) {
var countryCode = document.getElementById('<%=lstBillingCountryCode.ClientID%>').options[document.getElementById('<%=lstBillingCountryCode.ClientID%>').selectedIndex].value;
var currentStateValue = document.getElementById('<%=txtBillingState.ClientID%>').value;
var errorDiv = document.getElementById('reqBillingState');
if (countryCode == "US" && currentStateValue.trim() == '') {
errorDiv.style.display = 'block';
event.preventDefault();
//while stepping through this with firebug, it gets here fine but then it just gets ignored
}
else {
errorDiv.style.display = 'none';
}
});
</script>
$(“#”)单击(函数(事件){
var countryCode=document.getElementById(“”)。选项[document.getElementById(“”)。selectedIndex]。值;
var currentStateValue=document.getElementById(“”).value;
var errorDiv=document.getElementById('reqBillingState');
如果(countryCode==“US”&¤tStateValue.trim()==“U”){
errorDiv.style.display='block';
event.preventDefault();
//在firebug的帮助下,它很好地到达了这里,但随后就被忽略了
}
否则{
errorDiv.style.display='none';
}
});
试试:
不应将显示属性设置为“块”,而应设置为“”(空字符串)。按钮的默认显示是,将其设置为空字符串可使其返回默认值或CSS设置的任何值。
OnClientClick=" return showBillingRequiredState(this)"