Javascript函数调用服务器端方法不起作用

时间:2022-06-12 15:30:19

I'm trying to call a server side method in an ascx page through a javascript function. This method worked in an aspx page. It does not seem to call the javascript function but the hidden button does call the server side method.

我试图通过javascript函数在ascx页面中调用服务器端方法。此方法适用于aspx页面。它似乎没有调用javascript函数,但隐藏按钮确实调用服务器端方法。

<div runat="server">
<script type="text/javascript">

     function WebDatePicker_DayChange(sender, eventArgs)
     {
        document.getElementById("HiddenField3").value = eventArgs.get_value();
        var btn = document.getElementById("Button2");
        btn.click();
    }
 </script></div>


<ig:WebDatePicker runat="server" ID="WebDatePicker1" DropDownCalendarID="webMonthCalendar" DisplayModeFormat="MM/dd/yyyy" EditModeFormat="MM/dd/yyyy" EditMode="CalendarOnly" Nullable="False" AlwaysInEditMode="False" HorizontalAlign ="Center" >                
                    <ClientSideEvents  ValueChanged="WebDatePicker_DayChange" ></ClientSideEvents>             
                </ig:WebDatePicker>

                 <ig:WebMonthCalendar runat="server" ID="webMonthCalendar" Culture="en-us" FooterContent="Today: {0:d}"
                    EnableWeekNumbers="false"
                    ChangeMonthToDateClicked="true" 
                    EnableMonthDropDown="True"  
                    EnableYearDropDown="True">
                </ig:WebMonthCalendar>     
                <input type="button" id="Button2" style="display:none" runat="server"  onserverclick="WebDatePicker_DayChange" />
                <asp:HiddenField ID="HiddenField3" runat="server" Value=""  />

1 个解决方案

#1


2  

To trigger that method you need to run the following JavaScript code:

要触发该方法,您需要运行以下JavaScript代码:

__doPostBack('Button2','')

Replace btn.click(); with the code above.

替换btn.click();使用上面的代码。

That is an Asp.Net generated method [docs]

这是一个Asp.Net生成的方法[docs]

#1


2  

To trigger that method you need to run the following JavaScript code:

要触发该方法,您需要运行以下JavaScript代码:

__doPostBack('Button2','')

Replace btn.click(); with the code above.

替换btn.click();使用上面的代码。

That is an Asp.Net generated method [docs]

这是一个Asp.Net生成的方法[docs]