I have a Web Content Page in an ASP.NET 2005 Web Application project (the one that compiles all code-behind to one .DLL), using MS AJAX and VB.NET code-behind. I have several pages that allow users to maintain system tables (e.g. States, Countries, Departments, etc.) For some odd reason, when I click on the Add or Update ASP.NET Button controls, the PostBack doesn't always fire for the page. I proved this by running the web app in debug mode with breakpoints on the event handlers. It will fire if I re-click the button a second time. It always will work the second time at worst, and will never "not fire" more than once.
The page directive AutoEventWireup is set to false. I've use both the Handles btnUpdate.Click method of wiring up the even, as well as changing it to the markup declaration OnClick="btnUpdate_Click". Both of these methods will produce the the same behavior described above. This behavior also happens on all of these maintenance pages.
When I stated that the button doesn't always fire, it's because it may work if I don't click the GridView control on the page (the list of existing entities) when doing an Add. It sometimes will not fire when I do click on an existing entity in the GridView, change the value in a TextBox, and click Update.
This behavior doesn't happen on any other pages in my web app. The only commonality in these maintenance pages is that the pages are basically copies of each other for the most part, with the exception of the controls housing the details of the selected entity item (e.g. one text box on the Department Maintenance page for the Dept. name, but two TextBoxes on the State Maintenance page for the State Code and State name). I've googled around and haven't found anything similar to my issue. Any help would be appreciated.
An example .aspx page:
And the code-behind (pretty standard) with the Handles method commented out:
The page directive AutoEventWireup is set to false. I've use both the Handles btnUpdate.Click method of wiring up the even, as well as changing it to the markup declaration OnClick="btnUpdate_Click". Both of these methods will produce the the same behavior described above. This behavior also happens on all of these maintenance pages.
When I stated that the button doesn't always fire, it's because it may work if I don't click the GridView control on the page (the list of existing entities) when doing an Add. It sometimes will not fire when I do click on an existing entity in the GridView, change the value in a TextBox, and click Update.
This behavior doesn't happen on any other pages in my web app. The only commonality in these maintenance pages is that the pages are basically copies of each other for the most part, with the exception of the controls housing the details of the selected entity item (e.g. one text box on the Department Maintenance page for the Dept. name, but two TextBoxes on the State Maintenance page for the State Code and State name). I've googled around and haven't found anything similar to my issue. Any help would be appreciated.
An example .aspx page:
Code:
<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Master/AppMaster.Master"
CodeBehind="DeptMaint.aspx.vb" Inherits="<project name omitted for this thread>.DeptMaint" title="Department Maintenance" %>
<!-- more controls ommitted for forum posting -->
<asp:GridView ID="gvExisting"
runat="server"
AutoGenerateSelectButton="True"
CellPadding="2"
CellSpacing="1"
CssClass="gridViewMain"
GridLines="None"
AllowPaging="true"
Width="500px"
PageSize="15">
<EmptyDataRowStyle CssClass="gridViewRow" />
<RowStyle CssClass="gridViewRow" />
<SelectedRowStyle CssClass="gridViewSelectedRow" />
<HeaderStyle CssClass="gridViewHeader" />
<AlternatingRowStyle CssClass="gridViewAlternatingRow" />
</asp:GridView>
<br />
<asp:Label ID="lblName"
runat="server"
Text="Department Name:">
</asp:Label>
<asp:TextBox ID="txtName"
runat="server"
Width="300px"
AutoPostBack="True">
</asp:TextBox>
<br /><br />
<asp:Button ID="btnAdd"
runat="server"
Text="Add"
Width="64px"
OnClick="btnAdd_Click" />
<asp:Button ID="btnUpdate"
runat="server"
Text="Update"
Width="64px"
OnClick="btnUpdate_Click" />
<asp:Button ID="btnDelete"
runat="server"
Text="Delete"
Width="64px"
OnClick="btnDelete_Click" />
And the code-behind (pretty standard) with the Handles method commented out:
Visual Basic:
Protected Sub btnAdd_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) 'Handles btnAdd.Click
Try
Me.Add()
Catch ex As Exception
Throw
End Try
End Sub
Protected Sub btnDelete_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) 'Handles btnDelete.Click
Try
Me.Delete()
Catch ex As Exception
Throw
End Try
End Sub
Protected Sub btnUpdate_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) 'Handles btnUpdate.Click
Try
Me.Update()
Catch ex As Exception
Throw
End Try
End Sub
Protected Sub gvExisting_PageIndexChanging(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvExisting.PageIndexChanging
Try
MySession.PageIndex = e.NewPageIndex
Me.InitList()
Catch ex As Exception
Throw
End Try
End Sub
Protected Sub gvDepartments_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles gvExisting.SelectedIndexChanged
Try
If Me.gvExisting.SelectedRow IsNot Nothing Then
Me.txtName.Text = Server.HtmlDecode(Me.gvExisting.SelectedRow.Cells(2).Text).Trim
End If
Catch ex As Exception
Throw
End Try
End Sub