将数组值从一个click事件转移到另一个click事件 [英] transfer the array values from one click event to another

查看:78
本文介绍了将数组值从一个click事件转移到另一个click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要将数组值从一个click事件转移到另一个click事件.
怎么可能?

我已经尝试过ViewState,但是它仅用于传输单个值而不是数组.
:(
这是我的代码:

Need to transfer the array values from one click event to another.
How is it possible?

I have tried ViewState but it is useful only for transfering single value not array.
:(
Here is my Code:

String[] Id_To = new String[10];
 protected void CheckButton_Click(object sender, EventArgs e)
    {
        foreach (ListItem item in CheckBoxList1.Items)
        {
            if (item.Selected)
            {
                i++;
                Id_To[i] += item.Value.ToString();
            }
        }
    }



我需要将Id_To中存储的内容传输到SendButton_Click的另一个click事件中.



I need to transfer the content stored in Id_To into another click event of SendButton_Click.

protected void SendButton_Click(object sender, EventArgs e)
    {
      
    }





How is it possible?

推荐答案

检查示例..
Check the sample..
protected void Page_Load(object sender, EventArgs e)
{
 String[] myArray = { "1", "4", "5", "6", "7" };
 Session["arr"] = myArray;
}
protected void SendButton_Click(object sender, EventArgs e)
{
//you will have the myarray values in test.
String[] test = (String[])Session["arr"];
}



如果您想在CheckButton_Click事件中的会话中使用数组而不发生此事件,则从您的代码开始,如果您单击SendButton,则该会话将为空.



From your code as you want to use the array in session in CheckButton_Click event without happening of this event if you click on SendButton the session will be null.


存储该数组值在session ["Array"]

在其他情况下使用它,然后

清除该会话
store that array value in session["Array"]

use that in other event and then

clear that session


这篇关于将数组值从一个click事件转移到另一个click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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