If the execution order is not important and you need some kind of javascript AND some code to be run for the asp element, here is what you can do.
What you can take from my example: I have a div spanning an ASP control from which I want to run both javascript and codebehind. OnClick div method And the OnSelectionChanged calendar event both fire in this way.
In this example, I use the ASP Calendar control, and I control it from both javascript and codebehind:
Front End Code:
<div onclick="showHideModal();"> <asp:Calendar OnSelectionChanged="DatepickerDateChange" ID="DatepickerCalendar" runat="server" BorderWidth="1px" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ShowGridLines="true" BackColor="#B8C9E1" BorderColor="#003E51" Width="100%"> <OtherMonthDayStyle ForeColor="#6C5D34"> </OtherMonthDayStyle> <DayHeaderStyle ForeColor="black" BackColor="#D19000"> </DayHeaderStyle> <TitleStyle BackColor="#B8C9E1" ForeColor="Black"> </TitleStyle> <DayStyle BackColor="White"> </DayStyle> <SelectedDayStyle BackColor="#003E51" Font-Bold="True"> </SelectedDayStyle> </asp:Calendar> </div>
Codebehind:
protected void DatepickerDateChange(object sender, EventArgs e) { if (toFromPicked.Value == "MainContent_fromDate") { fromDate.Text = DatepickerCalendar.SelectedDate.ToShortDateString(); } else { toDate.Text = DatepickerCalendar.SelectedDate.ToShortDateString(); } }
Max Alexander Hanna Apr 16 '19 at 15:31 2019-04-16 15:31
source share