2014-01-18 89 views
2


我有這個JavaScript函數:
如何從asp.net中的代碼隱藏中調用javascript函數?

function showLoader() { 
      document.getElementById("loaderState").style.display = 'inline'; 
     } 


我有一個按鈕:

<asp:Button ID="btnSignUp" runat="server" Text="Sign Up" OnClick="btnSignUp_Click" /> 


我tryong來調用代碼的JS函數後面:

protected void btnSignUp_Click(object sender, EventArgs e) 
{ 
    try 
    { 
     int i = users.AddNewUser(); 
     if (i != 0) 
     { 
      Page.ClientScript.RegisterStartupScript(
       GetType(), 
       "btnSignUp", 
       "showLoader();", 
       true); 
     } 
    } 
    catch (Exception exp) 
    { 
     throw exp; 
    } 
} 


但沒有工作!爲什麼?
謝謝。

+0

你有什麼錯誤嗎? –

+1

您是否嘗試在'btnSignUp_Click'中評論所有內容,然後添加以下行:'Page.ClientScript.RegisterStartupScript(GetType(),「btnSignUp」,「showLoader();」,true);'?也許這是因爲'i'的值是0 – ekad

+0

不,我確定我不是0 – Farzaneh

回答

1

嘗試這個

protected void btnSignUp_Click(object sender, EventArgs e) 
{ 
    try 
    { 
     int i = users.AddNewUser(); 
     if (i != 0) 
     { 
ScriptManager.RegisterStartupScript(this, GetType(), "btnSignUp", "showLoader()", true); 

     } 
    } 
    catch (Exception exp) 
    { 
     throw exp; 
    } 
} 
+0

它不適用於我:( – Farzaneh

相關問題