Asp:Textbox visible="false"

In my form,
I have a hidden field:


<asp:TextBox ID="departmentid" runat="server" text="2" visible="false" />

Now when I attempt to insert a record into my table EMPLOYEES the departmentid value of 2 is never inserted in my field departmentid. All my other form entries are otherwise successful.

But, if I change the hidden TEXTBOX field to be visible
<asp:TextBox ID=“departmentid” runat=“server” text=“2” visible=“true” />

The insert function works as it should. It adds the 2 in my field departmentid for my table EMPLOYEES.

Why cant it insert a hidden value in ASP.net?

Why are you using TextBox and hiding it? Why not use


<asp:HiddenField ID="departmentid" runat="server" value="2" />

instead? Does it have to be visible sometimes but not others? Just wondering. :slight_smile:

I am following a tutorial by an author for Dreamweaver 8 unleashed as I am learning ASP.Net. I use Dreamweaver as my ASP.net authoring tool.

In my selection of ASP.net objects, I looked for the asp:HiddenField option but it is not listed. When I attempted to code it the way you suggest it, it doesnt like it.

BTW, I am coding ASP.Net/VB

Any other suggestions? Thanks for your response.

Hmm. I have no idea if this matters or not but what version of ASP.NET does your copy of dreamweaver use? What do you mean by “it doesn’t like it”?

Can you post the rest of your code for the page, as well as the error you get?

If you cannot use <asp:HiddenField>

use the following:

<input type=“hidden” runat=“server” id=“hdnControl” Value=“2” />

Then u can get it with hdnControl.Value

Hope this helps

NAWA-mark,
I am using Dreamweaver Version 8.0.2. I am not sure how I can tell which ASP.NET, I am using though. I am assuming its the latest.

Also, what I meant by “it doesn’t like it”…when I manually code it into my page, dreamweaver markup codes the ASP.NET objects a certain color. When I coded it with the ASP:HiddenField as you suggested, Dreamweaver doesnt recognize that object with the same particular color consistent with the other valid ASP.NET objects. Plus when I attempt to use that object in my SQL statement to insert the value into my table EMPLOYEES, the Dreamweaver wizard doesnt recognize that Object either.

Hawk,
No problem, here is my code:
I marked up the ASP code in BLUE and the ASP.NET object in question in RED.


[COLOR="Blue"]
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %>
<MM:Insert
runat="server"
CommandText='<%# "INSERT INTO Employees (BillingShippingAddress, BillingShippingCity, BillingShippingState, BillingShippingZip, DepartmentID, Email, Headshot, Name, Pass_word, Phone, Username) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" %>'
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_connDorknozzle") %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_DATABASETYPE_connDorknozzle") %>'
Expression='<%# Request.Form("MM_insert") = "form1" %>'
CreateDataSet="false"
SuccessURL='<%# "chap26x_newusercreated.aspx" %>'
><Parameters>
  <Parameter Name="@BillingShippingAddress" Value='<%# IIf((Request.Form("billshipaddress") <> Nothing), Request.Form("billshipaddress"), "") %>' Type="WChar" />
  <Parameter Name="@BillingShippingCity" Value='<%# IIf((Request.Form("billshipcity") <> Nothing), Request.Form("billshipcity"), "") %>' Type="WChar" />
  <Parameter Name="@BillingShippingState" Value='<%# IIf((Request.Form("billshipstate") <> Nothing), Request.Form("billshipstate"), "") %>' Type="WChar" />
  <Parameter Name="@BillingShippingZip" Value='<%# IIf((Request.Form("billshipzip") <> Nothing), Request.Form("billshipzip"), "") %>' Type="WChar" />
  <Parameter Name="@DepartmentID" Value='<%# IIf((Request.Form("departmentid") <> Nothing), Request.Form("departmentid"), "") %>' Type="Integer" />
  <Parameter Name="@Email" Value='<%# IIf((Request.Form("email") <> Nothing), Request.Form("email"), "") %>' Type="WChar" />
  <Parameter Name="@Headshot" Value='<%# IIf((Request.Form("headshotloc") <> Nothing), Request.Form("headshotloc"), "") %>' Type="WChar" />
  <Parameter Name="@Name" Value='<%# IIf((Request.Form("name") <> Nothing), Request.Form("name"), "") %>' Type="WChar" />
  <Parameter Name="@Pass_word" Value='<%# IIf((Request.Form("password") <> Nothing), Request.Form("password"), "") %>' Type="WChar" />
  <Parameter Name="@Phone" Value='<%# IIf((Request.Form("phonenumber") <> Nothing), Request.Form("phonenumber"), "") %>' Type="WChar" />
  <Parameter Name="@Username" Value='<%# IIf((Request.Form("username") <> Nothing), Request.Form("username"), "") %>' Type="WChar" />
</Parameters>
</MM:Insert>
<MM:PageBind runat="server" PostBackBind="true" />
[/COLOR]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- TemplateBeginEditable name="doctitle" -->
<title>The Dorknozzle Company Intranet</title>
<!-- TemplateEndEditable -->
<link href="Chapter 26/Beginning/DorknozzleASPX/styles.css" rel="stylesheet" type="text/css" />

<!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
</head>

<body bgcolor="#FFFFFF">
<table width="100%" border="0" cellpadding="0" cellspacing="0" background="Chapter 26/Beginning/DorknozzleASPX/Images/header_bg.gif" id="Header">
<tr>
<td background="Chapter 26/Beginning/DorknozzleASPX/Images/header_bg.gif"><img src="Chapter 26/Beginning/DorknozzleASPX/Images/header.gif" width="442" height="177" border="0" /></td>
</tr>
</table>
<table width="640" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="180" valign="top"><table width="170" border="0" align="center">
  <tr>
    <td width="24"><img src="Chapter 26/Beginning/DorknozzleASPX/Images/icon_arrow.gif" width="24" height="23" /></td>
    <td><a href="file:///P|/Website/DMX Unleashed 2004 Ed 3/760026/Beginning/DorknozzleASPX/index.aspx" class="link">Home</a></td>
  </tr>
  <tr>
    <td width="24"><img src="Chapter 26/Beginning/DorknozzleASPX/Images/icon_arrow.gif" width="24" height="23" /></td>
    <td><a href="file:///P|/Website/DMX Unleashed 2004 Ed 3/760026/Beginning/DorknozzleASPX/helpdesk.aspx" class="link">HelpDesk</a></td>
  </tr>
  <tr>
    <td width="24"><img src="Chapter 26/Beginning/DorknozzleASPX/Images/icon_arrow.gif" width="24" height="23" /></td>
    <td><a href="file:///P|/Website/DMX Unleashed 2004 Ed 3/760026/Beginning/DorknozzleASPX/companydirectory.aspx" class="link">Company Directory</a></td>
  </tr>
  <tr>
    <td width="24"><img src="Chapter 26/Beginning/DorknozzleASPX/Images/icon_arrow.gif" width="24" height="23" /></td>
    <td><a href="file:///P|/Website/DMX Unleashed 2004 Ed 3/760026/Beginning/DorknozzleASPX/employeestore.aspx" class="link">Employee Store</a></td>
  </tr>
  <tr>
    <td width="24"><img src="Chapter 26/Beginning/DorknozzleASPX/Images/icon_arrow.gif" width="24" height="23" /></td>
    <td><a href="file:///P|/Website/DMX Unleashed 2004 Ed 3/760026/Beginning/DorknozzleASPX/admin.aspx" class="link">Admin</a></td>
  </tr>
</table></td>
<td width="460" valign="top"><table width="460"  border="0" cellpadding="0" cellspacing="0" id="Content">
  <tr>
    <td><!-- TemplateBeginEditable name="Header Image" --><img src="Chapter 26/Beginning/DorknozzleASPX/Images/subheader_register.gif" width="92" height="26" /><!-- TemplateEndEditable --></td>
  </tr>
  <tr>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top"><form [COLOR="BLUE"]runat='server'[/COLOR] name='form1' method='POST' action="">
      <table width="450" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td colspan="2" bgcolor="#00CCFF">Personal Information </td>
          </tr>
        <tr>
          <td width="145">&nbsp;</td>
          <td width="305">[COLOR="Red"]
		  <asp:TextBox ID="departmentid" runat="server" Text="2" visible="false"/>[/Color][COLOR="BLUE"]
		  <asp:ValidationSummary DisplayMode="BulletList" HeaderText="The following needs attention:" ID="vsSummary" runat="server" />[/COLOR]</td>
        </tr>
        <tr>
          <td width="145">Name</td>
          <td width="305">[COLOR="BLUE"]
		  <asp:TextBox ID="name" runat="server" />
		  <asp:RequiredFieldValidator ControlToValidate="name" Display="None" ErrorMessage="Name required!" ID="rfvname" runat="server" />[/COLOR]</td>
        </tr>
        <tr>
          <td width="145">Username</td>
          <td width="305">[COLOR="BLUE"]
		  <asp:TextBox ID="username" runat="server" />
		  <asp:RequiredFieldValidator ControlToValidate="username" Display="None"  ErrorMessage="Username required!" ID="rfvusername" runat="server" />[/COLOR]</td>
        </tr>
        <tr>
          <td width="145">Password</td>
          <td width="305">[COLOR="BLUE"]
		  <asp:TextBox ID="password" runat="server" />
		  <asp:RequiredFieldValidator ControlToValidate="password" Display="None"  ErrorMessage="Password required!" ID="rfvpassword" runat="server" />[/COLOR]</td>
        </tr>
        <tr>
          <td width="145">Email</td>
          <td width="305">[COLOR="BLUE"]
		  <asp:TextBox ID="email" runat="server" />
		  <asp:RequiredFieldValidator ControlToValidate="email" Display="None"  ErrorMessage="Email required!" ID="rfvemail" runat="server" />
		  <asp:RegularExpressionValidator ControlToValidate="email" Display="Dynamic" ErrorMessage="Email is not formatted correctly" ID="regexEmail" runat="server" Text="i.e. [email]joe@domain.com[/email] or [email]joe@domain.com.us[/email]" ValidationExpression="^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$" />	[/COLOR]	  </td>
        </tr>
        <tr>
          <td width="145">Phone Number </td>
          <td width="305">[COLOR="BLUE"]
		  <asp:TextBox ID="phonenumber" runat="server" />
		  <asp:RequiredFieldValidator ControlToValidate="phonenumber" Display="None"  ErrorMessage="Phone number required!" ID="rfvphonenumber" runat="server" />
		  <asp:RegularExpressionValidator ControlToValidate="phonenumber" Display="Dynamic" ErrorMessage="Phone Number is not formatted correctly!" ID="regexphonenumber" runat="server" Text="i.e. 2222222222" ValidationExpression="^[2-9]\\d{9}$" />[/COLOR]		  </td>
        </tr>
        <tr>
          <td width="145">Headshot Location </td>
          <td width="305">[COLOR="BLUE"]
		  <asp:TextBox ID="headshotloc" runat="server" />
		  <asp:RequiredFieldValidator ControlToValidate="headshotloc" Display="None"  ErrorMessage="Headshot location required!" ID="rfvheadshot" runat="server" />
		  <asp:RequiredFieldValidator ControlToValidate="billshipaddress" Display="None"  ErrorMessage="Billing shipping address required!" ID="rfvbillshipaddress" runat="server" />[/COLOR]</td>
        </tr>
        <tr>
          <td width="145">Billing/Shipping Address </td>
          <td width="305">[COLOR="BLUE"]
		  <asp:TextBox ID="billshipaddress" runat="server" />[/COLOR]</td>
        </tr>
        <tr>
          <td width="145">Billing/Shipping City </td>
          <td width="305">[COLOR="BLUE"]
		  <asp:TextBox ID="billshipcity" runat="server" />
		  <asp:RequiredFieldValidator ControlToValidate="billshipcity" Display="None"  ErrorMessage="Billing shipping city required!" ID="rfvbillshipcity" runat="server" />[/COLOR]</td>
        </tr>
        <tr>
          <td width="145">Billing/Shipping State </td>
          <td width="305">[COLOR="BLUE"]
		  <asp:TextBox ID="billshipstate" runat="server" />
		  <asp:RequiredFieldValidator ControlToValidate="billshipstate" Display="None"  ErrorMessage="Billing shipping state required!" ID="rfvbillshipstate" runat="server" />[/COLOR]</td>
        </tr>
        <tr>
          <td width="145">Billing/Shipping Zip </td>
          <td width="305">[COLOR="BLUE"]
		  <asp:TextBox ID="billshipzip" runat="server" />
		  <asp:RequiredFieldValidator ControlToValidate="billshipzip" Display="None"  ErrorMessage="Billing shipping zip required!" ID="rfvbillshipzip" runat="server" />
		  <asp:RegularExpressionValidator ControlToValidate="billshipzip" Display="Dynamic" ErrorMessage="Zip code is not formatted correctly!" ID="regexZip" runat="server" Text="i.e. 12345" ValidationExpression="^\\d{5}$" />[/COLOR]		  </td>
        </tr>
        <tr>
          <td width="145">&nbsp;</td>
          <td width="305">&nbsp;</td>
        </tr>
        <tr>
          <td width="145">&nbsp;</td>
          <td width="305">[COLOR="BLUE"]<asp:Button ID="Submit" runat="server" Text="Submit Here" />[/COLOR]</td>
        </tr>
      </table>

        <input type="hidden" name="MM_insert" value="form1">
    </form>
    </td>
  </tr>
</table>

  </td>
</tr>
</table>
</body>
</html>

NightStalker-DNS,
Can you look at the code that I posted above? I am not sure how to go about it. Its late here…2 am Central U.S. time…time for me to hit the sack. My mind is mush now.
Thanks.

Ok, the way you are doing it:

Replace:
<asp:TextBox ID=“departmentid” runat=“server” Text=“2” visible=“false”/>

with:
<input type=“hidden” ID=“departmentid” name=“departmentid” Value=“2” />

If you are posting to the same page and using request.form, u do not need to use runat server.

The above should work for your example

Yep, that worked fine. But, if a malicious user wanted to change that hidden value, how would I validate it on the server side.

If I was using an ASP.Net Object, I would use a asp:RegularExpressionValidator object to validate it. I cant use this in the example you gave me.

Any suggestions?

Thanks.

I just read that HiddenField control is not available in ASP.NET 1.1, only in 2.0 and up.

NAWA-Mark,
Stupid question from me…How do I know which ASP.Net version I am using? I assume I am using ASP.NET 1.1 since I dont have HiddenField control. But would like to to know.

Thanks.

Update:
Nevermind I found out what ASP.NET is installed by going to c:\windows\Microsoft.NET and looked at the framework I have installed.

Unfortunately, I just found out DreamWeaver 8.0.2 does not support ASP.NET 2.0 I am bummed about that.

If you feel like a 3GB download you can try the Beta version of Visual Studio 2008 on microsoft.com.

Its most likely I will be going to that direction.

Thanks again for your quick responses.

If the visible attribute is set to false then the server control isn’t rendered to the page and it doesn’t produce any html output. I am assuming that means it doesn’t affect the page in any way nor is it processed on postback. Am I correct?

Also, was there a purpose given in the book for doing it?

I was following a tutorial from the book Macromedia Dreamweaver 8 Unleashed by the author Zak Ruvalcaba who ironically co-authored a book Sitepoint’s BUILD YOUR OWN ASP.NET 2.0 WEBSITE USING C# & VB.

Like I pointed out, the markup code within Dreamweaver 8.0.2 didnt recognized the ASP.Object by giving it an alternate color coding scheme when I manually coded it. Also when I ran it, it gave me an error. But I did noticed as you stated in a previous post the ASP.Net object HiddenId is not recognized in ASP.Net 1.1 which I was running.

I then downloaded the Microsoft.Net Framework 2.0 SDK which is huge. Installed it and made sure I was using ASP.Net 2.0. Now that I know I am using 2.0, I ran the same page again, and it works just fine now with the ASP.Net HiddenID object. Even though Dreamweaver 8.0.2 doesnt support ASP.Net 2.0 objects, at least I can manually enter those in.

But that being said, I think I have been re-directed into learning Visual Studio as my choice to code ASP.Net applications in the near future.

Thanks again for your follow-up Mark. :slight_smile:

Probably a good move. :slight_smile:

The pro version is expensive though :-\

No problem. I’m here to learn, too. :slight_smile:

Definately go for VS2008, even if you can only afford the free express edition. The full version is free while in Beta, though.

LINQ is going to amaze you when it comes to database access (only SQL server at atm; oracle hasn’t yet committed to an official LINQ to ORCL; MySQL and PostgreSQL are in the works by OS), XML handling, in-memory joins and queries.

Javascript intellisense and debugging is jaw-dropping. Really. It actually pseudo-evaluates the code on the fly to infer the type of a variable/parameter at any given point in code; then provides intellisense for members of that type. Even with in-line documentation. Amazing stuff.

IMO VS2008 CSS support is on par with DW and the design time experience when using server controls is much, much better.

LINQ is going to amaze you when it comes to database access (only SQL server at atm; oracle hasn’t yet committed to an official LINQ to ORCL; MySQL and PostgreSQL are in the works by OS), XML handling, in-memory joins and queries.

Not really believing this one too much. Maybe for very simple pojects, but that close a database dependency gives me the willies. Not to mention that some folks are finding some chinks in the armor in more complex query situations.