views:

543

answers:

9

I am using ASP.NET 3.5 and C#.

On my page I need to have a Text box that must not be visible to the user but it MUST be there when you look at the Page Source, reason being, another program called Eloqua will be looking at the page source and it must get the value of that text box.

The value of that text box will be populated based on what the user selects.

Thus, i cant set the text box propery to Visible = False because then it will not be in the source html and i cant set the Enabled = False because i do not want the user to see the text box.

Is there some property I can use to make this text box hidden to the user but still visible in the page source?

My ASP.NET text box

<asp:TextBox ID="txtTester" runat="server"></asp:TextBox>

Thanks in advanced!!

+1  A: 

Page.RegisterHiddenField or asp:HiddenField

Ruben Bartelink
+4  A: 

You can use a hidden field.

<asp:HiddenField id="myHiddenInput" runat="server" />

Use it just like a textbox.

Quintin Robinson
A: 

Why not use a hidden field:

<input type="hidden" name="blah" />
matpol
Because I am using ASP.NET, I cant specify a type
Etienne
+1  A: 

Try this to invisible textbox instead of server side Visible property :

myTextBox.Style.Add("visibility", "hidden");
// or :
myTextBox.Style.Add("display", "none");
Canavar
A: 

First thought: Can you use a hidden field? This would be much more suitable (<asp:hiddenfield ID="blah" runat="Server" /> if you want a .NET control).

If the app won't take that though you can actually just put "style='display: none;'" in the code-infront of the page. Intellisense won't like it, but it'll render just fine (EG: <asp:TextBox id="txtField" style="display: none;" runat="server" />)

Also from the codebehind you can do txtField.Attributes.Add("style", "display: none");

Or you could also just give it a CssClass "hidden" which in your CSS is defined as ".hidden { display: none;}"

The CSS class or just using a hidden field would be my recommendations.

Tim Schneider
A: 

If it must be a textbox for whatever reason just hide it with javascript:

<input type="text" name="blah" style="display:none" />
edosoft
A: 

CSS:

.hidden-div
{
    display: none;
}

HTML:

<div class="hidden-div">
    <input ... />
</div>

It will cause your input to be hidden, but it's gonna be visible in source code.

EDIT: Sorry, I misread it. I thought you wanted to hide an input. But it doesn't matter anyway, just replace input with basically anything.

Ondrej Slinták
display:none is probably more what you'd want. Visibility hidden would leave a gap in the middle of his form.
Tim Schneider
Stupid mistake, sorry. Edited :)
Ondrej Slinták
A: 

How about using CSS to hide a div containing the text box:

.hidden {
    position: absolute;
    left: -9999px;
}

Then within your page:

<div class="hidden">
    <asp:TextBox ID="TextBox1" runat="server" Text="hi"></asp:TextBox>
</div>

Hope this helps.

Mick Walker
A: 

By Setting Visible = "false" in server side will not render the control. You should either use asp:Hidden or INPUT type="hidden". Other option is using CSS, by setting display:none.

Anuraj