如何使用viewstate在回发后恢复我的价值? [英] how do I use viewstate to get my value back after postback?

查看:48
本文介绍了如何使用viewstate在回发后恢复我的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我在页面加载事件中有以下代码。

中的函数这个代码可以填充我的webform上的4个下拉列表。我有支持
回发,因为当用户从其中一个框中选择它时,它将根据在
$ b $中选择的数据过滤掉其他下拉列表。 b导致回发的一个。但是,当帖子后退运行时,下拉

框为空,列表中没有值。我意识到这是

,因为我还没有将数据重新加载到它们中,我当天的问题是:


我如何设置一个值到在回发被触发之前的viewstate和

然后如何在回发开始后将其恢复?


如果Page.IsPostBack = False那么

CreateComboDataSourceA()

CreateComboDataSourceB()

CreateComboDataSourceC()

CreateComboDataSourceD()

结束如果

谢谢,


Calvin X

解决方案

你应该有一个查看页面的EnsureChildControls。你需要

说出类似的话,


如果不是Page.IsPostBack那么

''Do Blah BLah Blah
Else

EnsureChildControls()

''在回帖中,现在应该可以下降了。

''Do Blah BLah Blah

结束如果


" Calvin X"写道:

大家好我在页面加载事件中有以下代码。这段代码中的函数可以填充我的webform上的4个下拉列表。我已经启用了回发功能,因为当用户从其中一个框中选择时,它应该根据在导致回发的一个中选择的数据来过滤其他下拉列表。但是,当回发运行时,下拉框
为空,列表中没有值。我意识到这是因为我还没有将数据重新加载到它们中,我当天的问题是:

如果我在触发回发之前将值设置到viewstate中并且<然后如何在回发开始后将其恢复?

如果Page.IsPostBack = False那么
CreateComboDataSourceA()
CreateComboDataSourceB()
CreateComboDataSourceC ()
CreateComboDataSourceD()
结束如果

谢谢,

Calvin X



你们今天提出了一些棘手的问题。


如果dropdownlistB中的选项绑定到A的选择,并且C绑定

到B和D绑定到C,你应该使用

的selectedIndexChange事件来填充下一个。


我可以'' t说我理解为什么你的下拉列表会在回发后失去他们的价值。如果你没有EnableViewState =" false"在任何地方,我都希望你的价值得以维持。所以我很清楚,这听起来像你一样

只是说DropDownListA有一堆选项,当一个是

选择它postback,在点DropDownListA没有值?


Karl


" Calvin X" <垃圾邮件 fr ********* **************@rotsnail.com >在消息中写道

新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...

大家好我在页面加载事件中有以下代码。这段代码中的函数可以填充我的webform上的4个下拉列表。我已经启用了回发功能,因为当用户从其中一个框中选择时,它应该根据
中选择的数据过滤其他下拉列表导致回发的数据。但是,当回发运行时,下拉框
为空,列表中没有值。我意识到这个
是因为我没有将数据重新加载到它们中,我当天的问题是:

如果我在触发回发之前将值设置到viewstate中并且<然后如何在回发开始后将其恢复?

如果Page.IsPostBack = False那么
CreateComboDataSourceA()
CreateComboDataSourceB()
CreateComboDataSourceC ()
CreateComboDataSourceD()
结束如果

谢谢,

Calvin X



我希望列表填充所有值。如果用户在

dropdownboxA中选择了一个项目,那么其他三个将通过

SelectedIndex_Changed事件进行更改,因为没有值而没有触发
$下拉控件中的b $ b。

所以我很清楚,听起来像你一样
只是说DropDownListA有一堆选项,如果选择了一个回发,那么DropDownListA没有值?

Karl



是的确实。


Calvin X


Hi all I have the following code in the page load event. The function in
this code works get to populate the 4 dropdownlists on my webform. I have
enabled postback because when the user selects from one of the boxes it
should filter the other dropdownlists according to the data selected in the
one causing the postback. However, when the post back runs the drop down
boxes are empty and there are no values in the list. I realize that this is
because I have not reloaded the data into them, my question of the day is:

How dow I set a value into the viewstate before the postback is fired and
then how do I get it back after the postback has started?

If Page.IsPostBack = False Then
CreateComboDataSourceA()
CreateComboDataSourceB()
CreateComboDataSourceC()
CreateComboDataSourceD()
End If
Thanks,

Calvin X

解决方案

you should have a look at the EnsureChildControls of the page. you need to
say something like,

If Not Page.IsPostBack Then
'' Do Blah BLah Blah
Else
EnsureChildControls()
'' In post back, drop downs should now be available.
'' Do Blah BLah Blah
End If

"Calvin X" wrote:

Hi all I have the following code in the page load event. The function in
this code works get to populate the 4 dropdownlists on my webform. I have
enabled postback because when the user selects from one of the boxes it
should filter the other dropdownlists according to the data selected in the
one causing the postback. However, when the post back runs the drop down
boxes are empty and there are no values in the list. I realize that this is
because I have not reloaded the data into them, my question of the day is:

How dow I set a value into the viewstate before the postback is fired and
then how do I get it back after the postback has started?

If Page.IsPostBack = False Then
CreateComboDataSourceA()
CreateComboDataSourceB()
CreateComboDataSourceC()
CreateComboDataSourceD()
End If
Thanks,

Calvin X



You guys are asking tough questions today.

If the choices in dropdownlistB are bound to the selection of A, and C bound
to B and D bound to C, you should be using the selectedIndexChange event of
each box to populate the next one.

I can''t say I understand why your dropdownlists are losing their values on
postback. If you don''t have EnableViewState="false" anywhere, I''d expect
your values to be maintained. So that I''m clear, it sounds to me like you
are simply saying that DropDownListA has a bunch of options, when one is
selected it postsback, at which point DropDownListA has no values?

Karl

"Calvin X" <spam fr***********************@rotsnail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

Hi all I have the following code in the page load event. The function in
this code works get to populate the 4 dropdownlists on my webform. I have
enabled postback because when the user selects from one of the boxes it
should filter the other dropdownlists according to the data selected in the one causing the postback. However, when the post back runs the drop down
boxes are empty and there are no values in the list. I realize that this is because I have not reloaded the data into them, my question of the day is:

How dow I set a value into the viewstate before the postback is fired and
then how do I get it back after the postback has started?

If Page.IsPostBack = False Then
CreateComboDataSourceA()
CreateComboDataSourceB()
CreateComboDataSourceC()
CreateComboDataSourceD()
End If
Thanks,

Calvin X



I want the lists to fill will all the values. If the user selects an item in
dropdownboxA then the other three will be altered via the
SelectedIndex_Changed event, which is not firing because there is no value
in the dropdown controls.

So that I''m clear, it sounds to me like you
are simply saying that DropDownListA has a bunch of options, when one is
selected it postsback, at which point DropDownListA has no values?

Karl


YES Exactly.

Calvin X


这篇关于如何使用viewstate在回发后恢复我的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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