你能在asp.net中使用结构吗? [英] Can you use structures in asp.net?

查看:54
本文介绍了你能在asp.net中使用结构吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在我的应用程序中有一个结构数组。每个

结构可能包含一些信息,如下所示:

结构MyStruct

FirstName as String

LastName as String

年龄为整数

结束结构

我会显示一系列网页,每个网页都会询问用户

LastName,FirstName和age。当他填写表格时,数值

进入数组。

问题是,在asp.net中,保存此信息的唯一方法
在会话变量中。这样,当

从一页到另一页时,数组信息不会丢失。因此,如果我在我的第一页的Page_Load过程中声明了数组及其结构

类型,那么

系列中的下一页将必须记住结构类型。有没有办法呢

这个?

- 谢谢,

Marvin

解决方案

Marvin,


有很多方法可以做到这一点。你提到了一个会话变量,

另一个是将结构直接存储在

clientmachine的viewstate中,这就是我通常所做的。为此,您需要使

结构可序列化。最简单的方法就是在

vb.net中声明它,你声明一个类,结构,whay让你可以序列化

放置< Serializable()> ;直接在对象声明前面。


< Serializable()> _

结构MyStruct

FirstName As String

LastName As String

年龄为int32

结束结构


-

此致,


S. Justin Gengo,MCP

网站开发人员/程序员

www.aboutfortunate.com


混乱就是订单。

Nietzsche

" COHENMARVIN" <共********* @ hotmail.com>在消息中写道

news:11 ********************** @ o13g2000cwo.googlegr oups.com ...

我希望在我的应用程序中有一个结构数组。每个
结构可能包含一些信息,如下所示:
结构MyStruct
FirstName as String
LastName as String
年龄为整数
结束结构我会显示一系列网页,每个网页都会询问用户姓名,姓名和年龄。当他填写表单时,值将进入数组。
问题是,在asp.net中,保存此信息的唯一方法是在会话变量中。这样,当
从一个页面到另一个页面时,数组信息不会丢失。因此,如果我在我的第一页的Page_Load过程中声明了数组及其结构
类型,那么
系列中的下一页将必须记住结构类型。有没有办法呢?
- 谢谢,
Marvin



感谢您的回答。我确实有另一个问题,那就是

,假设你有一组结构。你如何在viewstate中存储



Marvin


混沌和秩序不是敌人,只是对立面< br $>
Richard Garriott


对不起。没有办法。


ViewState是ASP.NET用来跟踪

服务器控制状态值的机制,否则不会回复为

HTTP表单的一部分。


结构数组不是服务器控件,

所以你无法跟踪它通过viewstate。


Juan T. Llibre,ASP.NET MVP

ASP.NET FAQ: http://asp.net.do/faq/

Foros de ASP.NET en Espa?ol: http://asp.net.do/foros/

======================================

" COHENMARVIN" <共********* @ hotmail.com>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com ...

感谢您的回答。我确实有另一个问题,那就是,假设你有一系列结构。你如何将视频存储在视图状态?
Marvin

混沌和秩序不是敌人,只是对立面
Richard Garriott


I want to have an array of structures in my application. Each
structure might hold some info, like this:
Structure MyStruct
FirstName as String
LastName as String
age as integer
End Structure
I would show a series of web pages, and each would ask the user for a
LastName, FirstName, and age. When he fills out the form, the values
go into the array.
The problem is, in asp.net, that the only way to hold this information
is in a session variable. That way the array info is not lost when
going from page to page. So if I declared the array and its Structure
type in a Page_Load procedure of my first page, the next pages in the
series would have to remember the Structure type. Is there a way to do
this?
-- Thanks,
Marvin

解决方案

Marvin,

There are many ways to do this. You mentioned one, session variables,
another would be to store the structure directly in viewstate on the
clientmachine, which is what I typically do. To do so you need to make the
structure serializable. The easiest way to do that is declare it so in
vb.net you declare a class, structure, whay have you as serializable by
placing <Serializable()> directly in front of the object declaration.

<Serializable()> _
Structure MyStruct
FirstName As String
LastName As String
Age As int32
End Structure

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"COHENMARVIN" <co*********@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

I want to have an array of structures in my application. Each
structure might hold some info, like this:
Structure MyStruct
FirstName as String
LastName as String
age as integer
End Structure
I would show a series of web pages, and each would ask the user for a
LastName, FirstName, and age. When he fills out the form, the values
go into the array.
The problem is, in asp.net, that the only way to hold this information
is in a session variable. That way the array info is not lost when
going from page to page. So if I declared the array and its Structure
type in a Page_Load procedure of my first page, the next pages in the
series would have to remember the Structure type. Is there a way to do
this?
-- Thanks,
Marvin



Thanks for your answer. I do have another question though, and that
is, suppose you have an array of structures. How would you store that
in viewstate?
Marvin

"Chaos and Order are not enemies, only opposites"
Richard Garriott


Sorry. No can do.

ViewState is the mechanism ASP.NET uses to keep track of
server control state values that don''t otherwise post back as
part of the HTTP form.

An array of structures is not a server control,
so you can''t track it through viewstate.


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Espa?ol : http://asp.net.do/foros/
======================================
"COHENMARVIN" <co*********@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...

Thanks for your answer. I do have another question though, and that
is, suppose you have an array of structures. How would you store that
in viewstate?
Marvin

"Chaos and Order are not enemies, only opposites"
Richard Garriott



这篇关于你能在asp.net中使用结构吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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