Hi,
I'm having a problem with something that used to work. I'm not sure what I did, but when I click on either of 2 buttons to submit, or on a DataGrid column header to submit/sort, the Page.Load event on the page does fire, but the handler/routine for the control that initiated the PostBack does NOT get called.
.ASPX file (3 controls in question):
---------------------------------------
<asp:datagrid id="MessagesDataGrid" runat="server"
accessKey="M" tabIndex="13"
Width="1081px" Height="30px" BorderWidth="1" CellPadding="2" BackColor="WhiteSmoke"
AllowSorting="True"
Font-Names="Arial" Font-Size="Medium">
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" Height="30px" ForeColor="White" CssClass="ms-formlabel DataGridFixedHeader" BackColor="#000084"></HeaderStyle>
</asp:datagrid>
<button id="ButDismissAlerts"
style="Z-INDEX: 105; LEFT: 928px; WIDTH: 104px; POSITION: absolute; TOP: 64px; HEIGHT: 40px"
accessKey="D" tabIndex="11" type="button" runat="server">Dismiss Alerts</button>
<button id="ButGo"
style="FONT-WEIGHT: bold; Z-INDEX: 109; LEFT: 484px; WIDTH: 60px; COLOR: rgb(255,255,255); POSITION: absolute; TOP: 71px; HEIGHT: 25px; BACKGROUND-COLOR: rgb(0,128,0)"
accessKey="O" tabIndex="7" type="button" runat="server">Go</button>
.ASPX.CS code:
------------------
public class Messages : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlButton ButDismissAlerts;
protected System.Web.UI.WebControls.DataGrid MessagesDataGrid;
protected System.Web.UI.HtmlControls.HtmlButton ButGo;
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.MessagesDataGrid.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.MessagesDataGrid_SortCommand);
this.ButGo.ServerClick += new System.EventHandler(this.ButGo_ServerClick);
this.ButDismissAlerts.ServerClick += new System.EventHandler(this.ButDismissAlerts_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);
}
private void Page_Load(object sender, System.EventArgs e)
{
// IsPostBack is true in the following cases:
// - A new refresh period has been requested by clicking "Go".
// - The "Dismiss Alerts" button has been clicked.
// - A new sort has been requested by clicking a column header.
if (IsPostBack)
{
// Get/Bind the message data from the previous page. Any refreshing of data or other
// processing will happen (subsequently) in the function that invoked the PostBack call.
MessagesDataGrid.DataSource = (DataView)Session["CurrentMessagesView"];
MessagesDataGrid.DataBind();
}
else
{
MessagesDataGrid.DataSource = CreateMessagesDataSource();
MessagesDataGrid.DataBind();
}
}
private DataView CreateMessagesDataSource()
{
// get data into dataset "ds"
DataView dv = new DataView(ds.Tables[0]); // for now
Session["CurrentMessagesView"] = new DataView(ds.Tables[0]); // for later (PostBack)
return dv;
}
private void ButGo_ServerClick(object sender, System.EventArgs e)
{
// event handling code
}
private void ButDismissAlerts_ServerClick(object sender, System.EventArgs e)
{
// event handling code
}
private void MessagesDataGrid_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
DataView dv = (DataView)MessagesDataGrid.DataSource;
dv.Sort = e.SortExpression;
MessagesDataGrid.DataBind();
}
}
I tried re-double-clicking on the two above buttons in the Designer view in VS2003 and they went straight to the handler routines as they should. After recompiling, setting break point in Page_Load, and restarting, the code breaks there as it should for the initial load, then again on the PostBack as well when a button or the grid header is clicked. BUT - breakpoints set in any of the handling routines never get reached. It's not strictly a DataGrid issue - the buttons have the same problem.
What could cause the event handlers to no longer get called? I've got to be doing something stupid, but I've been staring at it too long. Hopefully it's some easy points for someone. Thanks for any direction/help!
by: fizchPosted on 2006-05-22 at 12:24:00ID: 16737103
Make sure that your controls have autopostback set to true for each of the components you want to handle the event for. Sometimes the designer gets a little crazy and you can lose some of your settings.