2013-12-15 16 views
-1

我的aspx頁面:在Javascript中使用C#方法

<asp:TableCell> 
<asp:TextBox ID="tbFirstName" ClientIDMode="Static" runat="server" onblur="javascript:CheckFirstNameInput(this)"> 
     </asp:TextBox> 
    </asp:TableCell> 

我的C#類

[ScriptService()] 
public static class InputChecks 
{ 
[WebMethod()] 
    [ScriptMethod()] 
    public static bool CheckForLettersSpacesStripes(string input) 
    { //SomeCode }} 

我的母版

<asp:ScriptManager runat="server" ID="smScriptManager" EnablePageMethods="true"> 
    <Scripts> 
    <!-- And some standard imported scripts --> 
     <asp:ScriptReference Path="~/Resources/JavaScriptFunctions.js" /> 

    </Scripts> 
</asp:ScriptManager>  

,你可能會ñ otice,這個想法是,我在這裏導入一個JavaScript,它工作正常。測試它與一個警報和幾個console.logs和東西。但我無法達到C#方法,我使用了幾種方法。我用了一個ajax調用:

​​3210

但我也只是用了PageMethods。以上都沒有工作,我嘗試將腳本管理器放在aspx頁面而不是masterpages中,但沒有解決。我完全沒有想法,也沒有在網上找到任何新東西。那麼,有沒有人知道答案,我會永遠支持這個讓我擺脫這個煩人負擔的答案。

回答

0

您需要更改URL

變更網址:使用PageMethods

「應用程序路徑/ CheckForLettersSpacesStripes」,

或嘗試其它方法之一: 「測試」,以網址

您不需要任何線路,只需使用此代碼代替您的代碼

PageMethods.CheckForLettersSpacesStripes(input); 

referred from

+0

我想在此之前,pagemethods返回undefined和正確的URL(對不起,我沒有把合適的人,我測試的東西是最後一次)也返回一個未定義的。在兩種情況下,我都會輸入正確顯示的輸入值。 – Jardo