What is Hidden Field in ASP.NET?
The hidden field is a control that stores a value but does not display that value to the user. It would be similar to using a label that had a value, but was hidden. The hidden field is rendered as an HTML element. The hidden field can be used to store data that needs to persist across multiple post backs. This control can come in handy when other methods of storing data across post backs are not available, such as session states and cookies.
Yes, it is possible to find a good web host. Sometimes it takes a while to find one you are comfortable with. After trying several, we went with Server Intellect and have been very happy thus far. They are by far the most professional, customer service friendly and technically knowledgeable host we’ve found so far.
to access the hidden field from a javascript function, we can add in a button to the Default.aspx page as follows:
<input type="submit" name="btnDisplay" value="Click Me!" onclick="displayHiddenValue()" />
//set our label text to the value of our hiddenfield
Label1.Text = HiddenField1.Value;
Then, we can simply add in the following JavaScript function to run on the event that our button is clicked to display the hidden field value:
function displayHiddenValue()
{
alert(form1.HiddenField1.value);
}
The hidden field is a control that stores a value but does not display that value to the user. It would be similar to using a label that had a value, but was hidden. The hidden field is rendered as an HTML element. The hidden field can be used to store data that needs to persist across multiple post backs. This control can come in handy when other methods of storing data across post backs are not available, such as session states and cookies.
Yes, it is possible to find a good web host. Sometimes it takes a while to find one you are comfortable with. After trying several, we went with Server Intellect and have been very happy thus far. They are by far the most professional, customer service friendly and technically knowledgeable host we’ve found so far.
Using the HiddenField
There are two different ways that you might want to use the hidden
field, from a javascript function or from the code behind of our page.
In this example, we will be demonstrating both ways. To do this, create a
new ASP.NET Empty Web Site and:- Right click the project in your solution explorer.
- Select add new item…
- Select a web form.
- Name it ‘Default.aspx’.
- Click add.
- Open Default.aspx up to design mode.
- Drag and drop a label onto the web form.
- Drag and drop a hiddenfield onto the web form.
- Set the Value property of the hiddenfield to ‘Hello Hidden Field!’.
to access the hidden field from a javascript function, we can add in a button to the Default.aspx page as follows:
<input type="submit" name="btnDisplay" value="Click Me!" onclick="displayHiddenValue()" />
//set our label text to the value of our hiddenfield
Label1.Text = HiddenField1.Value;
Then, we can simply add in the following JavaScript function to run on the event that our button is clicked to display the hidden field value:
function displayHiddenValue()
{
alert(form1.HiddenField1.value);
}
No comments:
Post a Comment