不能摆脱观点 [英] Cant get rid off viewstate

查看:61
本文介绍了不能摆脱观点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我在运行时生成的一些复选框出现问题。

在表单中,我绘制了一些html复选框,每个chekbox代表一个有点

" department"用户链接到。问题是,当回发生成
且页面重新加载时,复选框

的旧状态(已选中)仍然存在,尽管我明确将其设置为false。 />
要说明问题,只需创建一个表单,拖动一个面板(或

占位符,它相同)和一个按钮,并将此代码放入page_load

事件:


for(int i = 0; i< 10; i ++)


{

HtmlInputCheckBox chk = new HtmlInputCheckBox();


chk.ID =" chk_" + i.ToString();


chk.Name = chk.ID;


chk.Checked = false;


Panel1.Controls.Add(chk);


}


无论你是否设置了enabledviewstate如果在面板中或在

页面中显示错误,您将看到在点击按钮后,检查将与您之前离开的时间相同。


我在面板的controlcollection里面用FindControl检查它的空白......


我怎么能避免这个? ??如何在每次点击中将复选框设置为false?


提前谢谢.-

Hi there
Im having problems with some checkbox generated at runtime.
In a form, i draw some html checkboxes, each chekbox represents a kinda
"department" the user is linked to. The problems is that when a postback is
generated and the page reloads, the old state (checked) of the checkboxes
remains although i explicit set it to false.
To ilustrate the problem, simply create a form, drag a panel (or
placeholder, its the same) and a button and put this code in page_load
event:

for(int i = 0; i < 10; i++)

{

HtmlInputCheckBox chk = new HtmlInputCheckBox();

chk.ID = "chk_" + i.ToString();

chk.Name = chk.ID;

chk.Checked = false;

Panel1.Controls.Add(chk);

}

No matter if you set "enabledviewstate" to false in the Panel or the in the
page, you will see that after hiting the button the checks will be as you
left they before.

I check with FindControl inside the controlcollection of the panel and its
empty...

How can i avoid that???? How can i set the checkbox to false in every hit?

Thanks in advance.-

推荐答案

尝试在代码中将EnableViewState属性显式设置为False

chk.EnableViewState = false;


希望这会有所帮助。发布按原样提供


" Mariano Drago" < MD **** @ softhome.net>在留言中写道

新闻:O7 ************** @ TK2MSFTNGP10.phx.gbl ...
Try Explicitly Sett the EnableViewState property to False in your code
chk.EnableViewState = false;

Hope this helps. Posting is provided as is

"Mariano Drago" <md****@softhome.net> wrote in message
news:O7**************@TK2MSFTNGP10.phx.gbl...
你好
我在运行时生成的一些复选框有问题。
在一个表单中,我绘制一些html复选框,每个chekbox代表一个有点
部门。用户链接到。问题是当生成回传
并且页面重新加载时,复选框的旧状态(已选中)仍然存在,尽管我明确将其设置为false。
要说明问题,只需创建一个表单,拖动一个面板(或
占位符,它相同)和一个按钮,并将此代码放入page_load
事件:

for(int i = 0; i< 10; i ++)



HtmlInputCheckBox chk = new HtmlInputCheckBox();

chk.ID =" chk_" ; + i.ToString();

chk.Name = chk.ID;

chk.Checked = false;

Panel1.Controls.Add (chk);

}

无论你是否设置了enabledviewstate如果在面板或
页面中出现错误,您会看到在点击按钮后,检查将在您之前离开时。

我检查面板的controlcollection里面的FindControl并且它空了......

我怎么能避免那个????如何在每次点击中将复选框设置为false?

提前致谢.-
Hi there
Im having problems with some checkbox generated at runtime.
In a form, i draw some html checkboxes, each chekbox represents a kinda
"department" the user is linked to. The problems is that when a postback
is
generated and the page reloads, the old state (checked) of the checkboxes
remains although i explicit set it to false.
To ilustrate the problem, simply create a form, drag a panel (or
placeholder, its the same) and a button and put this code in page_load
event:

for(int i = 0; i < 10; i++)

{

HtmlInputCheckBox chk = new HtmlInputCheckBox();

chk.ID = "chk_" + i.ToString();

chk.Name = chk.ID;

chk.Checked = false;

Panel1.Controls.Add(chk);

}

No matter if you set "enabledviewstate" to false in the Panel or the in
the
page, you will see that after hiting the button the checks will be as you
left they before.

I check with FindControl inside the controlcollection of the panel and its
empty...

How can i avoid that???? How can i set the checkbox to false in every hit?

Thanks in advance.-



明确地尝试在代码中将EnableViewState属性设置为False

chk.EnableViewState = false;


希望这会有所帮助。发布按原样提供


" Mariano Drago" < MD **** @ softhome.net>在留言中写道

新闻:O7 ************** @ TK2MSFTNGP10.phx.gbl ...
Try Explicitly Sett the EnableViewState property to False in your code
chk.EnableViewState = false;

Hope this helps. Posting is provided as is

"Mariano Drago" <md****@softhome.net> wrote in message
news:O7**************@TK2MSFTNGP10.phx.gbl...
你好
我在运行时生成的一些复选框有问题。
在一个表单中,我绘制一些html复选框,每个chekbox代表一个有点
部门。用户链接到。问题是当生成回传
并且页面重新加载时,复选框的旧状态(已选中)仍然存在,尽管我明确将其设置为false。
要说明问题,只需创建一个表单,拖动一个面板(或
占位符,它相同)和一个按钮,并将此代码放入page_load
事件:

for(int i = 0; i< 10; i ++)



HtmlInputCheckBox chk = new HtmlInputCheckBox();

chk.ID =" chk_" ; + i.ToString();

chk.Name = chk.ID;

chk.Checked = false;

Panel1.Controls.Add (chk);

}

无论你是否设置了enabledviewstate如果在面板或
页面中出现错误,您会看到在点击按钮后,检查将在您之前离开时。

我检查面板的controlcollection里面的FindControl并且它空了......

我怎么能避免那个????如何在每次点击中将复选框设置为false?

提前致谢.-
Hi there
Im having problems with some checkbox generated at runtime.
In a form, i draw some html checkboxes, each chekbox represents a kinda
"department" the user is linked to. The problems is that when a postback
is
generated and the page reloads, the old state (checked) of the checkboxes
remains although i explicit set it to false.
To ilustrate the problem, simply create a form, drag a panel (or
placeholder, its the same) and a button and put this code in page_load
event:

for(int i = 0; i < 10; i++)

{

HtmlInputCheckBox chk = new HtmlInputCheckBox();

chk.ID = "chk_" + i.ToString();

chk.Name = chk.ID;

chk.Checked = false;

Panel1.Controls.Add(chk);

}

No matter if you set "enabledviewstate" to false in the Panel or the in
the
page, you will see that after hiting the button the checks will be as you
left they before.

I check with FindControl inside the controlcollection of the panel and its
empty...

How can i avoid that???? How can i set the checkbox to false in every hit?

Thanks in advance.-



Nop,它起作用了。
Nop, it dosent work.


这篇关于不能摆脱观点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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