会话未被创建/使用

时间:2015-06-18 04:37:00

标签: c# asp.net

我编写了这个代码,我在其中创建了一个会话,但我不确定会话是否未创建或未被使用

    Session["user"] = this.txtUser.Text.Trim();

我试图从以下网址获取会话值的页面:

   protected void Page_Load(object sender, EventArgs e)
   {
    if (Session["user"] == null)
    {
        txtName.Text = Session["user"].ToString();
    }

2 个答案:

答案 0 :(得分:3)

更改您的代码
dzip -j4 myfile

...

CFILE file = cfopen("myfile.dz", "r");
off_t some_offset = 673820;
cfseek(file, some_offset);
char buf[100];
cfread(buf, 100, 1, file);
cfclose(file);

到这个

if (Session["user"] == null)
    {
        txtName.Text = Session["user"].ToString();
    }
在Page_Load

因为在Session为null时设置txtName的Text属性。事实并非如此,因为会话具有TextBox的先前值。

答案 1 :(得分:1)

在获取会话值时,代码应如下所示,

public class MainActivity extends Activity {

    private ImageView myImage;
    private static final String IMAGEVIEW_TAG = "The Android Logo";

/** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        myImage = (ImageView)findViewById(R.id.image);
         // Sets the tag
        myImage.setTag(IMAGEVIEW_TAG);

        // set the listener to the dragging data
        myImage.setOnLongClickListener(new MyClickListener());

        findViewById(R.id.toplinear).setOnDragListener(new MyDragListener());
        findViewById(R.id.bottomlinear).setOnDragListener(new MyDragListener());

    }

    private final class MyClickListener implements OnLongClickListener {

        // called when the item is long-clicked
        @Override
        public boolean onLongClick(View view) {
        // TODO Auto-generated method stub

            // create it from the object's tag
            ClipData.Item item = new ClipData.Item((CharSequence)view.getTag());

            String[] mimeTypes = { ClipDescription.MIMETYPE_TEXT_PLAIN };
            ClipData data = new ClipData(view.getTag().toString(), mimeTypes, item);
            DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);

            view.startDrag( data, //data to be dragged
                            shadowBuilder, //drag shadow
                            view, //local data about the drag and drop operation
                            0   //no needed flags
                          );


            view.setVisibility(View.INVISIBLE);
            return true;
        }  
    }

    class MyDragListener implements OnDragListener {
        Drawable normalShape = getResources().getDrawable(R.drawable.normal_shape);
        Drawable targetShape = getResources().getDrawable(R.drawable.target_shape);

        @Override
        public boolean onDrag(View v, DragEvent event) {

            // Handles each of the expected events
            switch (event.getAction()) {

            //signal for the start of a drag and drop operation.
            case DragEvent.ACTION_DRAG_STARTED:
                // do nothing
                break;

            //the drag point has entered the bounding box of the View
            case DragEvent.ACTION_DRAG_ENTERED:
                v.setBackground(targetShape);   //change the shape of the view
                break;

            //the user has moved the drag shadow outside the bounding box of the View
            case DragEvent.ACTION_DRAG_EXITED:
                v.setBackground(normalShape);   //change the shape of the view back to normal
                break;

            //drag shadow has been released,the drag point is within the bounding box of the View
            case DragEvent.ACTION_DROP:
                // if the view is the bottomlinear, we accept the drag item
                  if(v == findViewById(R.id.bottomlinear)) {
                      View view = (View) event.getLocalState();
                      ViewGroup viewgroup = (ViewGroup) view.getParent();
                      viewgroup.removeView(view);

                      //change the text
                      TextView text = (TextView) v.findViewById(R.id.text);
                      text.setText("The item is dropped");

                      LinearLayout containView = (LinearLayout) v;
                      containView.addView(view);
                      view.setVisibility(View.VISIBLE);
                  } else {
                      View view = (View) event.getLocalState();
                      view.setVisibility(View.VISIBLE);
                      Context context = getApplicationContext();
                      Toast.makeText(context, "You can't drop the image here",
                                                 Toast.LENGTH_LONG).show();
                      break;
                   }
                  break;

            //the drag and drop operation has concluded.
            case DragEvent.ACTION_DRAG_ENDED:
                v.setBackground(normalShape);   //go back to normal shape

            default:
                break;
            }
            return true;
        }
    }
}