在单个循环中存储多个会话

在单个循环中存储多个会话

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

问题描述

大家好,
我有一个关于如何在单个循环中存储多个会话值的查询.这是我的代码:
它是一个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.

推荐答案

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];
            }
        }
    }


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!!!!!!!


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!!!


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

09-25 14:56