hidden inputs and viewstate

  • Thread starter Thread starter dawidg
  • Start date Start date
D

dawidg

I have an asp.net page with viewstate disabled. I have a control on
the page that dynamically creates controls inside itself, no
viewstate. The controls aren't created in Init, but in Load.

With Viewstate disabled, a few hidden inputs appear in the beginning
of the page, all name h_*. Nowhere in my code do I create these. The
problem is that these hidden input create errors on postback if my
controls doesn't create the same number of controls. this is the
error:

An error has occurred because a control with id 'ctl14' could not be
located or a different control is assigned to the same ID after
postback. If the ID is not assigned, explicitly set the ID property of
controls that raise postback events to avoid this error.


Here's the inputs I'm talking about:
<body>
<form name="form1" method="post" action="Module.aspx?
tvid=32&amp;TableId=10&amp;ViewType=1" id="form1">
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT"
value="" />
<input type="hidden" name="h_ctl14" id="h_ctl14" value="" />
</div>



Why are these h_* inputs created?
 
Hello dawidg,

There is no such controls by default.
Try to create empy page to verify that.

Do u use any 3rd party libs?

---
WBR,
Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


d> I have an asp.net page with viewstate disabled. I have a control on
d> the page that dynamically creates controls inside itself, no
d> viewstate. The controls aren't created in Init, but in Load.
d>
d> With Viewstate disabled, a few hidden inputs appear in the beginning
d> of the page, all name h_*. Nowhere in my code do I create these. The
d> problem is that these hidden input create errors on postback if my
d> controls doesn't create the same number of controls. this is the
d> error:
d>
d> An error has occurred because a control with id 'ctl14' could not be
d> located or a different control is assigned to the same ID after
d> postback. If the ID is not assigned, explicitly set the ID property
d> of controls that raise postback events to avoid this error.
d>
d> Here's the inputs I'm talking about:
d> <body>
d> <form name="form1" method="post" action="Module.aspx?
d> tvid=32&amp;TableId=10&amp;ViewType=1" id="form1">
d> <div>
d> <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value=""
d> /
d> <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT"
d> value="" />
d> <input type="hidden" name="h_ctl14" id="h_ctl14" value="" />
d> <input type="hidden" name="h_ctl16" id="h_ctl16" value="" />
d> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="...="
d> /
d> </div>
d>
d> Why are these h_* inputs created?
d>
 
you are using a 3rd party control that creates hidden fields based on its
name. as you have not assigned an id to the control, it assigned by the
server. on postback you are not creating the controls in the same order, so
the names are different. just explicitly name the controls.

-- bruce (sqlwork.com)
 
Back
Top