Link to home
Start Free TrialLog in
Avatar of wolfcoop
wolfcoop

asked on

Easy points for hidden fields and setting value in code behind file

Can you set hidden form field values in the code behind file when enable view state is set to false???
Here is my code:

Dim hidDenCanc As HiddenField = FormView11.FindControl("hidCancDeny")

        hidDenCanc.Value = "Yes"

but when the round trip is made from the server, the hidden form field is back to its original value when checking for t on the page load event.
Avatar of divinewind80
divinewind80

Just to be sure, are you setting this code in the following:

If Not IsPostBack() Then
Dim hidDenCanc As HiddenField = FormView11.FindControl("hidCancDeny")
End If

Otherwise, you will be reseting every time...
Avatar of wolfcoop

ASKER

No its set in selectedindexchanged sub routine of a drop down, so it does not get set unless the value of the drop down is changed.  The problem is the drop down gets changed, and the value gets set

Dim hidDenCanc As HiddenField = FormView11.FindControl("hidCancDeny")

        hidDenCanc.Value = "Yes",

then the page travels to the server showing a couple of new drop downs, but on the Page load event the hidden form field has the original value, not the value set by the sub routine.  View state is not enabled, so does it just load in a fresh page, with the original form field values???  Hence the hidden variable gets set and then to the server and gets dropped because its not passed back???????
 
It sounds as if the PageLoad event, or the control's OnLoad event is indeed setting the value back to its default.  I assume this control is not created dynamically, correct?

If this is the case, you should be able to use the Not IsPostBack.  This will make it only rebind the data if the page is loaded for the first time... not on every postback.

Can you show more code?
its ok I figured it out.  I am a moron.  I just gave up on setting the hidden field value, and read the drop down list selected value in the onload.  if it = Select then its not the cancel deny process, but any ther value and I take them back to the cancel/deny view of the multiview.  Thanks for trying, but a solution is better than knowledge at this point.  And to answer your question no its a hard coded hidden field on the particular multiview view.

Page load did not reference the control other than checking the value of the hidden field, and the control has no onload event defined.  No worries though, its working now, was just banging my head up against it.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial