如何preserve用户输入回发字面控制? [英] How to preserve user input in literal control on postback?

查看:97
本文介绍了如何preserve用户输入回发字面控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Page_Init,如果是回来后,我检查是否被点击了一个名为Button1的按钮,如果是这样我添加了一个LiteralControl一个名为Panel1的面板:

On Page_Init, if is post back, I check if a button called Button1 was clicked, if so I add a LiteralControl to a Panel called Panel1:

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

正如你所看到的,它只是文字输入code:,接着一个名为TXT code文本框

As you can see, it is just the text "Enter Code:" followed by a TextBox called txtCode.

我有第二个按钮(Button2的),点击后,我想检索TXT code输入的文本:

I have a second button (Button2) that, when clicked, I would like to retrieve the text entered in txtCode:

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

我不知道如何做到这一点?我怎样才能在TXT code输入的文字?

I'm not sure how to do this... How can I get the text entered in txtCode?

推荐答案

您可以随时使用的的Request.Form 的集合:

You can always use the Request.Form collection:

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

这将包含发布与当前请求所有值,无论是服务器端控件或没有。

It will contain all values posted with the current request, regardless of being server side controls or not.

这篇关于如何preserve用户输入回发字面控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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