gpt4 book ai didi

c# - 如何在回发的文字控件中保留用户输入?

转载 作者:太空宇宙 更新时间:2023-11-03 21:53:43 24 4
gpt4 key购买 nike

在 Page_Init 上,如果回发,我检查是否单击了名为 Button1 的按钮,如果是,我将 LiteralControl 添加到名为 Panel1 的面板:

Panel1.Controls.Add(new LiteralControl("Enter Code:<input type=\"text\" name=\"txtCode\"></td>"));  

如您所见,它只是文本“输入代码:”,后跟一个名为 txtCode 的文本框。

我有第二个按钮 (Button2),单击它时,我想检索在 txtCode 中输入的文本:

protected void Button2_Click(object sender, EventArgs e)
{
foreach (Control c in Panel1.Controls)
{
if (c is LiteralControl) ...
}
}

我不确定该怎么做...我怎样才能在 txtCode 中输入文本?

最佳答案

您始终可以使用Request.Form 集合:

string txtCode = Request.Form["txtCode"];

它将包含随当前请求发布的所有值,无论是否是服务器端控件。

关于c# - 如何在回发的文字控件中保留用户输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13259505/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com