简体   繁体   中英

Asp button disables the month change on asp calendar

I have an asp calendar which works fin normally but when I add a asp button to submit the the textbox values in form the calendar only shows current month the previous and next month buttons doesn't work.

<form id="form1" runat="server">
    <div>
        <asp:Calendar ID="cal2" runat="server" Width="50%" DayField="Date" OnDayRender="Calendar1_DayRender"
            BackColor="Orange" NextMonthText="Next" PrevMonthText="Prev" OnVisibleMonthChanged="Calendar1_VisibleMonthChanged" >
            <DayStyle CssClass="days" VerticalAlign="Top" Font-Name="Arial" Width="100px" Height="100px" BackColor="lightYellow"  />
             <TodayDayStyle BackColor="Orange"  />
            <OtherMonthDayStyle BackColor="LightGray" ForeColor="DarkGray"/>
        </asp:Calendar>
        </div>
    <asp:Button ID="submit" CssClass="login" runat="server" Text="Submit" OnClick="Submit_click" /> 
</form>

I have some textboxes which I have post back to the server side and for that I need to use the asp button, how can I prevent it from disabling the calendar functions? Thanks in advance

The problem is with the name (ID) of your button. The Calender component uses an internal (javascript) call to form.submit(), introducing a button with this ID breaks that call.

Example fix:

<asp:Button ID="MySubmit" CssClass="login" runat="server" Text="Submit" OnClick="Submit_click" />

(This is not unique to the Calendar component, in general you should not name your buttons "submit" in ASP.NET unless you know exactly what you are doing)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM