更改视图时表中的按钮NullPointer [英] Button NullPointer in table when changing View

查看:65
本文介绍了更改视图时表中的按钮NullPointer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

我得到一个NullPointer Exeption,用于放置在表中的按钮.我想更改视图以将数据填充到几个标签,文本框和表格中.在第一页上显示表格和其中的按钮,并且该按钮可以正常使用.当我更改为"Button_Change"时,我得到了Exeption,我不知道为什么导致相同的代码,我只想更改文本.

.aspx:

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:

<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:



.aspx.cs:

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.

推荐答案

也许Button1并非在创建时您尝试更改文本.
看一下Loaded Event(我对asp.net并不熟悉,但这在WPF中会有所帮助).祝你好运
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


这篇关于更改视图时表中的按钮NullPointer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆