Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hey together,

i get a NullPointer Exeption for a button placed in a table. I want to change the view to fill data in several labels, textboxes and the table. On the first page the table and the button in it is shown, and the button works right. When i change to "Button_Change" i get the Exeption and i don´t know why cause it´s the same code, i only want to change the text.

.aspx:
C#
<asp:Button ID="Button_Add" runat="server" CommandName="SwitchViewByID" CommandArgument="0" Text="Add" OnClick="ActiveViewChanged"></asp:Button>
<asp:Button ID="Button_Change" runat="server" CommandName="SwitchViewByID" CommandArgument="0" Text="Change" OnClick="ActiveViewChanged"></asp:Button>
<asp:Button ID="Button_Delete" runat="server" CommandName="SwitchViewByID" CommandArgument="1" Text="Delete" OnClick="ActiveViewChanged"></asp:Button>
//CommandArgument="0" for Add and Change because structure is the same

...
<asp:Label ID="Label_Name" runat="server" Text="Name: "></asp:Label> <br />
<asp:TextBox ID="TextBox_Name" runat="server"></asp:TextBox><br /><br /> 
<asp:Label ID="Label_Group" runat="server" Text="Group: "></asp:Label><br />
<asp:TextBox ID="TextBox_Group" runat="server"></asp:TextBox>
...
<asp:Table ID="Table_1" runat="server">
    <asp:TableRow ID="TableRow_1" runat="server">
        <asp:TableCell ID="TableCell1" runat="server">
            <asp:Button ID="Button1" runat="server" Text="Hallo" OnClick="button_Click" /></asp:TableCell>
        <asp:TableCell ID="TableCell2" runat="server"></asp:TableCell>
        ...
    </asp:TableRow>
</asp:Table>


.aspx.cs:

C#
protected void createMethod()
        {
             Button1.Text = "Other Test";//here the NullPointer
        }


protected void button_Click(object sender, EventArgs e)
        {
            ((Button)sender).Text= "Test";
        }


I have no idea why it acts like this, hope you can help me and thanks for your help.
Posted

1 solution

Maybe the Button1 isn't created at the time when you try to change the Text.
Look at the Loaded Event (I'm not familiar with asp.net, but that would help in WPF). Good luck
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900