Despite the fact that I have placed my asp:Button inside an UpdatePanel, it is still triggering a postback on the full page the first time it's clicked. Also, the OnClick event isn't being caught the first time I click the button either, but every single time after that everything works fine.
Any ideas what could be causing this problem? See the code below.
(In my Site.Master file)
<asp:ScriptManager runat="server" AjaxFrameworkMode="Enabled" EnablePartialRendering="true" ValidateRequestMode="Disabled">
</asp:ScriptManager>
(In my actual webpage)
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Editor.aspx.cs" Inherits="Technology.WebForm1"
validateRequest="false" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<textarea id="htmlTexarea" runat= "server" style="height: 90%"></textarea>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="testBtn" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Button ID="testBtn" style="" runat="server" ClientIDMode="Static" OnClick="testBtn_Click" UseSubmitBehavior="false" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
My C# codebehind is:
protected void Page_Init(object sender, EventArgs e) {
testBtn.Click += testBtn_Click;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void testBtn_Click(object sender, EventArgs e)
{
String test = "Helloworld";
}
Is there anything I've left out or have done wrong?
EDIT: I added the following to the C# code behind:
protected void Page_Load(object sender, EventArgs e)
{
//Should return POST, returns GET on first click
String test = Request.HttpMethod;
if (!IsPostBack)
{
//stops here first time
String hello = "Hello world";
}
else {
//should stop here
String hello = "Hello world";
}
}
The first time I click the button the server is getting a GET request and IsPostBack
is returning false, without changing anything every other click sends a POST request and IsPostBack
is true. Anyone know what could be causing this?