Add the C3 of this line to your code behind file:

    Protected WithEvents button1 As System.Web.UI.WebControls.Button

Just expand the #Region " Web Form Designer Generated Code " and add a
reference there to the button. 



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: vrijdag 8 oktober 2004 16:58
To: [EMAIL PROTECTED]
Subject: [AspNetAnyQuestionIsOk] DataList question



Hello everybody! :)
I hope somebody can give me some advice on how to solve this:
I have a very simple DataList defined like this:

<asp:datalist id="DataList1" runat="server" Width="90%" 
HorizontalAlign="Center">
   <HeaderTemplate>
      <asp:Button ID="Button1" Runat="server" Text="New 
Entry"></asp:Button>
   </HeaderTemplate>

   <ItemTemplate>
      <Table width="100%" cellspacing="5">
         <tr>
         <td>Name:</td>
         <td><%# DataBinder.Eval(Container.DataItem, "Name") %></td>
         </tr>
         <tr>
         <td>Email:</td>
         <td><%# DataBinder.Eval(Container.DataItem, "Email") %></td>
         </tr>
         <tr>
         <td>Website:</td>
         <td><%# DataBinder.Eval(Container.DataItem, "Website")%></td>
         </tr>
      </Table>
   </ItemTemplate>
</asp:datalist>


Now the problem is with the "Button1" defined in the HeaderTemplate, 
for some reason it does not seem to be recognized by the code behind 
class:

....
protected System.Web.UI.WebControls.Button Button1;
....
private void InitializeComponent()
{
   this.Button1.Click += new System.EventHandler(this.Button1_Click);
   this.Load += new System.EventHandler(this.Page_Load);
}
....
private void Button1_Click(object sender, System.EventArgs e)
{
   Console.WriteLine("Button1 Clicked!");
}

The first line in the InitializeComponent method gives me this 
runtime error:
"Object reference not set to an instance of an object"

Now if in the aspx page I take Button1 outside the DataList is works 
fine ... What am I doing wrong in the DataList then?? :(


Thank you very much for your help :)


Victor.








 
Yahoo! Groups Links



 





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to