ASP.NET 中的文本框控件不属于表单视图的一部分

发布于 2024-08-28 07:20:59 字数 1628 浏览 10 评论 0原文

我必须在由许多文本框组成的表单中添加一个文本框,并在末尾添加一个按钮。它有一个数据源,所有数据都在表单加载中加载,按钮更新文本框的值。问题是:这个特定的文本框不会在数据源中,我想从 web.config 中获取它,并且我已经设法更改其他页面中的 web.config,但在这种情况下,文本框 ID不会出现在页面本身的代码隐藏中的智能感知中,因此我认为除了表单的纯绑定之外,任何其他内容都无法访问它。

<asp:FormView>
<EditItemTemplate>
    <asp:TextBox ID="id" runat="server" Text='<%# bind("field") %>'/>
    <asp:TextBox ID="id2" runat="server" Text='<%# bind("field2") %>'/>
    <asp:TextBox ID="id3" runat="server" Text='<%# bind("field3") %>'/>

    <asp:TextBox ID="THIS_ONE" runat="server"></asp:TextBox> <!--HERE-->

    <asp:Button ID="UpdateButton" runat="server" SkinID="UpdateButton" CommandName="Update"/>

</EditItemTemplate>
</asp:FormView>

上面,我有一个无法访问的文本框。

<asp:FormView>
<EditItemTemplate>
    <asp:TextBox ID="id" runat="server" Text='<%# bind("field") %>'/>
    <asp:TextBox ID="id2" runat="server" Text='<%# bind("field2") %>'/>
    <asp:TextBox ID="id3" runat="server" Text='<%# bind("field3") %>'/>

    <asp:Button ID="UpdateButton" runat="server" SkinID="UpdateButton" CommandName="Update"/>

</EditItemTemplate>
</asp:FormView>

    <asp:TextBox ID="THIS_ONE" runat="server"></asp:TextBox><!--HERE-->

在上面,我有一个可访问的文本框,但在更新按钮下面。

我已经尝试在文本框之前关闭 EditItemTemplate 并在之后重新打开它。不起作用。

我当然可以将它放在按钮下方,表单结束的下方,那么它们就不会成为表单的一部分,这样就可以了,但是如果我想要文本框位于按钮上方怎么办?我想要在 ASP.NET 表单视图中访问未绑定的文本框。这可能吗?

ps.:我知道在运行时弄乱 web.config 的影响,并且我知道这似乎没有经过精心计划,但我没有说一些与这个问题无关的细节。

I have to add a textbox inside a form that is composed of a lot of textboxes, and one button at the end. It has a datasource, all data is loaded in formload, and the button updates the values of the textboxes. The thing is: this particular textbox won't be in the datasource, I want to get this from the web.config, and I've already managed to change the web.config in other page, but in this case, the textbox ID won't appear in intellisense in the code-behind of the page itself, so I figured it's unaccessible to anything besides the pure binding of the form.

<asp:FormView>
<EditItemTemplate>
    <asp:TextBox ID="id" runat="server" Text='<%# bind("field") %>'/>
    <asp:TextBox ID="id2" runat="server" Text='<%# bind("field2") %>'/>
    <asp:TextBox ID="id3" runat="server" Text='<%# bind("field3") %>'/>

    <asp:TextBox ID="THIS_ONE" runat="server"></asp:TextBox> <!--HERE-->

    <asp:Button ID="UpdateButton" runat="server" SkinID="UpdateButton" CommandName="Update"/>

</EditItemTemplate>
</asp:FormView>

Above, I have an unaccessible textbox.

<asp:FormView>
<EditItemTemplate>
    <asp:TextBox ID="id" runat="server" Text='<%# bind("field") %>'/>
    <asp:TextBox ID="id2" runat="server" Text='<%# bind("field2") %>'/>
    <asp:TextBox ID="id3" runat="server" Text='<%# bind("field3") %>'/>

    <asp:Button ID="UpdateButton" runat="server" SkinID="UpdateButton" CommandName="Update"/>

</EditItemTemplate>
</asp:FormView>

    <asp:TextBox ID="THIS_ONE" runat="server"></asp:TextBox><!--HERE-->

Above, I have an accessible textbox, but BELOW the update button.

I've already tried closing EditItemTemplate before the textbox and re-opening it afterwards. Doesn't work.

I could of course put it below the button, below where the form ends, then they wouldn't be part of the form, and that would work, but what if I want the textboxes ABOVE the button ? I want accessible unbinded textboxes inside an ASP.NET formview. Is that possible ?

ps.: I know the implications of messing with web.config in run-time and I know that this doesn't seem well planned, but I didn't say some details that don't matter for this question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新人笑 2024-09-04 07:20:59

如果您在尝试访问文本框时遇到问题?您可以使用 FormView1.FindControl() 获取对表单视图中控件的引用...

If your issue trying to access the textbox? You can use FormView1.FindControl() to obtain a reference to the control within the formview...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文