Saturday, March 24, 2012

Working with hidden input controls and Visual Studio .Net 2003

What is the best/recommended way to add a hidden input control to a webform
within Visual Studio? I'm using vb.net and code behind (probably implied
with Visual Studio).
What I did was to add the following on the .aspx page:
<input id="CurrentStep" type="hidden" value="" runat="server"
NAME="CurrentStep">
And then I added this in the Web Form Designer Generated Code Section:
Protected WithEvents CurrentStep As System.Web.UI.HtmlControls.HtmlInputHidd
en
Am I missing something? Is there a better way to add that type of control?
Thanks!Yes, that's one way. The other is to use Page.RegisterHiddenField.
-Brock
DevelopMentor
http://staff.develop.com/ballen

> What is the best/recommended way to add a hidden input control to a
> webform within Visual Studio? I'm using vb.net and code behind
> (probably implied with Visual Studio).
> What I did was to add the following on the .aspx page:
> <input id="CurrentStep" type="hidden" value="" runat="server"
> NAME="CurrentStep">
> And then I added this in the Web Form Designer Generated Code Section:
> Protected WithEvents CurrentStep As
> System.Web.UI.HtmlControls.HtmlInputHidden
> Am I missing something? Is there a better way to add that type of
> control?
> Thanks!
>
I guess the other thing I was wondering with respect to this is if there's a
way to automate this with VS (like adding any other control), and if not if
I
was putting that information in the correct place on the code behind page.
Lastly, I was wondering if that method is better than using the ViewState.
"Brock Allen" wrote:

> Yes, that's one way. The other is to use Page.RegisterHiddenField.
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
>
> I guess the other thing I was wondering with respect to this is if
> there's a way to automate this with VS (like adding any other
> control), and if not if I was putting that information in the correct
> place on the code behind page.
There's not much difference technically. It's just which ever approach you
like.

> Lastly, I was wondering if that method is better than using the
> ViewState.
The big difference there is that any javascript you write on the page can
set something into the hidden to have it sent back to the server when the
form is submitted. This is far too difficult if the data's inside of viewsta
te
somewhere. But, if you don't need javascript to modify the value and you
just want it passed back to the server on a post, the view state is far easi
er.
-Brock
DevelopMentor
http://staff.develop.com/ballen

0 comments:

Post a Comment