0

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.

<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=""  />
4
  • 1
    User Control Elements have different ID.. View the page source in browser and check the ID of the Element and try the same... Commented Apr 1, 2013 at 15:31
  • possible duplicate of Call ASP.NET Function From Javascript? Commented Apr 1, 2013 at 15:34
  • The problem is that my js function is not being called at all. this worked in an aspx page but is not working here. Commented Apr 1, 2013 at 16:05
  • Pandian solved my question. The control id's were getting changed when the page was loaded. Learned something new. Commented Apr 1, 2013 at 16:27

1 Answer 1

2

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

__doPostBack('Button2','')

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

That is an Asp.Net generated method [docs]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.