I have multiple asp:buttons
in my application that reload the page whenever they are clicked. How do I resolve this behavior while still allowing the function of the button to work? Besides looking weird when the page reloads, I have a tab style navigation section that defaults back to the first tab every time a button is clicked. Here's an example of one button and the C# code that goes with it.
HTML/ASPX
<asp:Button ID="uxRequestFEMAResponseBtnT3" runat="server" Text="Generate Interim Response Email" OnClick="uxRequestFEMAResponseBtnT3_Click" />
<asp:TextBox ID="uxFEMARequestDateTxtBox" runat="server" style="color: red; text-align:center;"></asp:TextBox>
C#
protected void uxRequestFEMAResponseBtnT3_Click(object sender, EventArgs e)
{
String today = DateTime.Now.ToString("dd/MM/yyyy");
uxFEMARequestDateTxtBox.Text = today;
}
What I've tried so far:
I have tried multiple fixes to resolve this issue. I initially thought I could resolve it by wrapping the entire body section (which includes all of the buttons) in a <asp:UpdatePanel ID="UpdatePanel1" runat="server">
...'', but that did not work. Second, I tried just adding AutoPostBack="False"
inside the <asp:Button..>
tag, but nothing changed. I then changed all of the asp: buttons
to simple html <input type="button"...>
with the same onClick
event. This stopped the reload, but the functionality (adding DateTime to the textbox in the C#) no longer worked. I've seen several possible jQuery solutions, but I am not sure if that will resolve my issue either. I am pretty new to ASP.NET but this seems like a common problem that anyone using the Web.Controls.UI
buttons would run into. Any suggestions as to how to resolve this?