我有這個jQuery的功能:jQuery函數不是從C#代碼調用
<script>
function tabSelected() {
//alert('tab.');
$('.nav-tabs li:eq(3) a').tab('show');
};
</script>
這個功能是從後面的代碼名爲:
ScriptManager.RegisterClientScriptBlock(this, typeof(string), "script", "tabSelected()", true);
或:
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "tabSelected()", true);
沒有它作品。應該在c#方法「ValidateData」中調用jquery:
private bool ValidateData()
{
try
{
if (ddlStatusOp.SelectedIndex <= 0)
{
ScriptManager.RegisterClientScriptBlock(this, typeof(string), "script", "tabSelected()", true);
throw new Exception("'Status' must be selected.");
}
return true;
}
catch (Exception ex)
{
throw ex;
}
我在做什麼錯?
可能沒有閱讀http://stackoverflow.com/help/mcve –
它不起作用?如果您取消註釋,警報是否會觸發? F12控制檯是否有任何錯誤? –
不相關的,但如果你重新拋出同樣的異常,你通常只想'throw;',而不是'throw ex;' - 它會保留現有的堆棧跟蹤等。 –