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.- 10 1691
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... 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.-
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... 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.-
I also look inside the HttpContext for the cached checkboxes (they must be
somewhere!) and found nothing :(
I also look inside the HttpContext for the cached checkboxes (they must be
somewhere!) and found nothing :(
Hi,
earlier your code to put them unchecked is otherwise correct, but you need
to do that (putting them unchecked) in PreRender as postback data loading
for CheckBoxes (or dynamical controls generally) is done after Page_Load.
And yes, disabling ViewState won't help because this isn't controlled by
ViewState at all.
I've discussed the same behaviour, though with TextBoxes in my blog post: http://blogs.aspadvice.com/joteke/ar...03/15/767.aspx
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist http://blogs.aspadvice.com/joteke
"Mariano Drago" <md****@softhome.net> wrote in message
news:Oa**************@TK2MSFTNGP10.phx.gbl... I also look inside the HttpContext for the cached checkboxes (they must be somewhere!) and found nothing :(
Hi,
earlier your code to put them unchecked is otherwise correct, but you need
to do that (putting them unchecked) in PreRender as postback data loading
for CheckBoxes (or dynamical controls generally) is done after Page_Load.
And yes, disabling ViewState won't help because this isn't controlled by
ViewState at all.
I've discussed the same behaviour, though with TextBoxes in my blog post: http://blogs.aspadvice.com/joteke/ar...03/15/767.aspx
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist http://blogs.aspadvice.com/joteke
"Mariano Drago" <md****@softhome.net> wrote in message
news:Oa**************@TK2MSFTNGP10.phx.gbl... I also look inside the HttpContext for the cached checkboxes (they must be somewhere!) and found nothing :(
Thanks for the answer Teemu.
I readed the blog... and now i understand the problem.
Knowing that, i simple get rid of the checkbox and use:
Label lb = new Label();
lb.Text = "<input name='chk_"+i.ToString()+"' id='chk_"+i.ToString()+"'
type='checkbox' />";
Panel1.Controls.Add(ln);
It isnt elegant, i know, but it works ;)
Thanks again!
"Teemu Keiski" <jo****@aspalliance.com> escribió en el mensaje
news:ex**************@TK2MSFTNGP09.phx.gbl... Hi,
earlier your code to put them unchecked is otherwise correct, but you need to do that (putting them unchecked) in PreRender as postback data loading for CheckBoxes (or dynamical controls generally) is done after Page_Load. And yes, disabling ViewState won't help because this isn't controlled by ViewState at all.
I've discussed the same behaviour, though with TextBoxes in my blog post: http://blogs.aspadvice.com/joteke/ar...03/15/767.aspx
-- Teemu Keiski MCP, Microsoft MVP (ASP.NET), AspInsiders member ASP.NET Forum Moderator, AspAlliance Columnist http://blogs.aspadvice.com/joteke
"Mariano Drago" <md****@softhome.net> wrote in message news:Oa**************@TK2MSFTNGP10.phx.gbl... I also look inside the HttpContext for the cached checkboxes (they must
be somewhere!) and found nothing :(
Thanks for the answer Teemu.
I readed the blog... and now i understand the problem.
Knowing that, i simple get rid of the checkbox and use:
Label lb = new Label();
lb.Text = "<input name='chk_"+i.ToString()+"' id='chk_"+i.ToString()+"'
type='checkbox' />";
Panel1.Controls.Add(ln);
It isnt elegant, i know, but it works ;)
Thanks again!
"Teemu Keiski" <jo****@aspalliance.com> escribió en el mensaje
news:ex**************@TK2MSFTNGP09.phx.gbl... Hi,
earlier your code to put them unchecked is otherwise correct, but you need to do that (putting them unchecked) in PreRender as postback data loading for CheckBoxes (or dynamical controls generally) is done after Page_Load. And yes, disabling ViewState won't help because this isn't controlled by ViewState at all.
I've discussed the same behaviour, though with TextBoxes in my blog post: http://blogs.aspadvice.com/joteke/ar...03/15/767.aspx
-- Teemu Keiski MCP, Microsoft MVP (ASP.NET), AspInsiders member ASP.NET Forum Moderator, AspAlliance Columnist http://blogs.aspadvice.com/joteke
"Mariano Drago" <md****@softhome.net> wrote in message news:Oa**************@TK2MSFTNGP10.phx.gbl... I also look inside the HttpContext for the cached checkboxes (they must
be somewhere!) and found nothing :(
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Russell |
last post by:
Morning,
I have been having trouble with a my embedded user control not being
able to see the view state that I set in its parent page.
I have done a test with the following and I still cant...
|
by: John Kirksey |
last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
|
by: Steve Drake |
last post by:
All,
I have a CONTROL that contains 1 control (Control ONE), the 1 control that
it can contain 1 or 2 control (Control A and B).
Control A, raises and event and Control ONE receives this event...
|
by: neo |
last post by:
hi,
I am studying ASP.NET and have few questions -
1) The session ID and values of controls is stored in VIEWSTATE
variable. So now when we put EnableViewState="false" in Page directive and...
|
by: Mariano Drago |
last post by:
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...
|
by: et |
last post by:
I'm not sure I understand the use of the ViewState.
Do I understand correctly that values of controls are automatically held in
a hidden control called ViewState?
If so, then why can't we get...
|
by: Steve Richter |
last post by:
In my user control I want to read the ViewState dictionary of the
Parent control. But this sensible idea is not permitted by the
compiler:
Compiler Error Message: CS1540: Cannot access...
|
by: Mark Broadbent |
last post by:
Been a while since I've touched asp.net but one thing that always seems to
fustrate me is the loss of state on variable declarations. Is there anyway
(i.e. assigning an attribute etc) to instruct...
|
by: hitendra15 |
last post by:
Hi
I have created web user control which has Repeater control and
Linkbutton in ItemTemplate of repeater control, following is the code
for this control
On first load it runs fine but when...
|
by: Nick C |
last post by:
Hi
How can i reduce the viewstate for my asp.net application. It is getting
very large now. What is a good solution?
thanks
N
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |