简体   繁体   English

为什么我不能使用(文本框的 ID).text = "test";

[英]why cant i use (id of a textbox).text = "test";

Cannot change text in a asp:TextBox.无法更改 asp:TextBox 中的文本。

I cannot change the text in the asp:TextBox in my onclick function from the code behind.我无法从后面的代码更改我的 onclick function 中的 asp:TextBox 中的文本。

And I've tried a lot of things (stupid things) but it all didnt work, even other people in the office didnt know what to do.而且我尝试了很多事情(愚蠢的事情),但都没有奏效,甚至办公室里的其他人也不知道该怎么做。

and now i'm hoping one of you guys know what i need to do.现在我希望你们中的一个人知道我需要做什么。

// .asp.cs file
protected void updateProduct_OnClick(object sender, EventArgs e)
{
    prodName.Text = "test";
}
<table>
                <tr><td>
                        <asp:Label runat="server" Text="Name" />
                    </td><td>
                        <asp:TextBox runat="server" ID="prodName"/>
                </td></tr><tr><td>
                    <asp:Label runat="server" Text="Description" />
                    </td><td>
                        <asp:TextBox runat="server" ID="productDescription" />
                </td></tr><tr><td>
                    <asp:Label runat="server" Text="catagory"/>
                    </td><td>
                        <asp:TextBox runat="server" ID="productCategory"/>
                </td></tr><tr><td>
                    <asp:Label runat="server" Text="price"/>
                </td><td>
                    <asp:TextBox runat="server" ID="productPrice"/>
                </td></tr><tr><td>
                    <asp:LinkButton runat="server" OnClick="OnClick" Text="Add"></asp:LinkButton> |
                    <asp:LinkButton runat="server" OnClick="onSave" Text="save(update)"></asp:LinkButton>
                </td></tr>
            </table>

I've found what the problem whas, it what that it all whas located out of the updatepanel and contenttemplate.我发现问题出在哪里,这一切都在更新面板和内容模板之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM