문제

코드를보고 있습니다 이것 웹 방법에 관한 기사와 나는 그것을 구현하려고 노력했다. 이 기사는 설계된대로 작동하지만 ASP : 버튼에 HTML 버튼을 교환하면 결과가 다릅니다.

뒤에 코드 :

    [WebMethod]
    public static string GetCurrentDate()
    {          
        return DateTime.Now.ToString();
    }

ASPX 페이지 :

JS :

<script type="text/javascript">
    function UpdateTime() {
        $get('Label6').innerHTML = PageMethods.GetCurrentDate(OnSucceeded,
                                   OnFailed); 
 }

 function OnSucceeded(result, userContext, methodName) {
   $get('Label6').innerHTML = result; 
 }

 function OnFailed(error, userContext, methodName) {
   $get('Label6').innerHTML = "An error occured.";
 }
</script>

그리고 다른 마크 업

<form id="form1" runat="server">
    <asp:ScriptManager EnablePageMethods="true" 
        ID="ScriptManager2" runat="server">
    </asp:ScriptManager>

<div id="usingWebMethods">
        <asp:Label runat="server" 
            Text="Using WebMethods" 
            ID="Label5" />
        <br />

        <asp:Label 
            runat="server" 
            Text="Web Method Update!" 
            ID="Label6" />
        <asp:Button ID="Button3" 
            runat="server" 
            Text="Postback Update" 
            OnClientClick="UpdateTime();" 
            UseSubmitBehavior="False" />      
        <input type="button" 
            id="Button4" 
            value="Web Method Update" 
            onclick="UpdateTime();" />


</div>
</form>

버튼에 두 가지를 발견했습니다. 버튼이 오류가 발생했으며 레이블이 변경 되더라도 ViewState가 업데이트되지 않습니다.

이 두 가지 문제가 발생하는 이유는 무엇이며 해결하기 위해 무엇을 할 수 있습니까?

도움이 되었습니까?

해결책

ViewState는 PostBack에서만 업데이트됩니다. 당신은 True Ajax를 사용하고 있습니다. 당신이 한 일을 알 수있는 방법이 없습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top