Bug in ASP.net

N

nhsu

I have found that a databound control will not postback correctly if
you access its control collection in the Init stage. Obviously, the
control collection would be empty at this point as long as if have not
called DataBind, but simply accessing it will mess up the postback.
Here is the code, I've included the checkbox to force a postback.

Default2.aspx

<%@ Page Language="C#" AutoEventWireup="false"
CodeFile="Default2.aspx.cs" Inherits="Default2"
EnableEventValidation="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="fv_Object" runat="server">
<InsertItemTemplate>
<asp:TextBox ID="tbx" runat="server" />
</InsertItemTemplate>
</asp:FormView>
</div>
<asp:CheckBox ID="cbx" AutoPostBack="true" runat="server" />
</form>
</body>
</html>

Default2.aspx.cs

using System;
using System.Web;
using System.Web.UI;

public partial class Default2 : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
// Comment this line out, and the FormView will post back
correctly
ControlCollection x = fv_Object.Controls;
base.OnInit(e);
}
}
 
C

Christopher Reed

Well, I just tried your code and I didn't have any issues. Are you getting
an error? How can you tell that this is a problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top