在单个循环中存储多个会话变量 [英] Storing multiple Session Variables in a single loop

查看:63
本文介绍了在单个循环中存储多个会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个关于如何在单个循环中存储多个会话值的查询.这是我的代码:
它是一个function()

Hi folks,
i have a query regarding, how to store multiple session values in a single loop.Here is my code:
Its a function()

void ClearInputs(ControlCollection cs)
    {
        foreach (Control c in cs)
        {
            if (c is TextBox)
            {
                Session["New"] = ((TextBox)c).Text;
                lbl_savesubmit1.Text += Session["New"];
            }
        }
    }



并在提交按钮中调用函数,如:

ClearInputs(Page.Controls);



任何帮助将不胜感激.



and in submit button am calling function like:

ClearInputs(Page.Controls);



any help will be appreciated.

推荐答案

即使我不了解此工具的实用程序,也请尝试以下操作:

Even if I do not understand the utility of this thing, try this:

void ClearInputs(ControlCollection cs)
    {
        foreach (Control c in cs)
        {
            if (c is TextBox)
            {
                Session[c.ID] = ((TextBox)c).Text;
                lbl_savesubmit1.Text += Session[c.ID];
            }
        }
    }


您好,

我也不明白您要解决的情况,希望以下代码段可以帮助您解决问题.


Hello,

I also doesn''t understand the scenario you want to resolve, Hope following code snippet will help you to solve your problem.


void ClearInputs(ControlCollection cs)
        {
            List<String> lstSessions = new List<string>();
            foreach (Control c in cs)
            {
                if (c is TextBox)
                {
                    lstSessions.Add(((TextBox)c).Text);
                    lbl_savesubmit1.Text += ((TextBox)c).Text;
                }
            }
            Session["TxtSession"] = lstSessions;
        }



谢谢!!!!!!!



Thanks!!!!!!!



如果使用母版页,则必须遍历所有容器才能到达控件.希望对您有帮助.

Hi,
If you are using Master Pages you have to iterate through all the containers to reach the control. Hope this will help you.

protected void Button1_Click(object sender, EventArgs e)
    {
       // if(!IsPostBack)
        ClearInputs(Page.Controls);
    }

    void ClearInputs(ControlCollection cs)
    {
       
        foreach (Control container in cs)
        {
            foreach (Control childContainer in container.Controls)
            {
                foreach (Control innerChild in childContainer.Controls)
                {
                    foreach (Control control in innerChild.Controls)
                    {
                        if (control is TextBox)
                        {
                            ((TextBox)control).Text = string.Empty;
                            Session[childContainer.ID] = ((TextBox)control).Text;
                            lbl_savesubmit1.Text += Session[childContainer.ID];
                        }
                    }
                }
            }
        }
    }



谢谢!!!



Thanks!!!


这篇关于在单个循环中存储多个会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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