可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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 property to Visible = False because then it will not be in the source HTML and I can't 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>
回答1:
You can use a hidden field.
<asp:HiddenField id="myHiddenInput" runat="server" />
Use it just like a textbox.
回答2:
Try this to invisible textbox instead of server side Visible property :
myTextBox.Style.Add("visibility", "hidden");
// or :
myTextBox.Style.Add("display", "none");
回答3:
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.
回答4:
Page.RegisterHiddenField or asp:HiddenField
回答5:
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.
回答6:
If it must be a textbox for whatever reason just hide it with css:
<input type="text" name="blah" style="display:none" />
回答7:
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.
回答8:
Why not use a hidden field:
<input type="hidden" name="blah" />
回答9:
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.
回答10:
Simply, Try to create a CSS class
and attach it to your TextBox
as the following:
CSS Class Style
<style>
.Hide {
display:none;
}
</style>
Textbox using CssClass="Hide"
<asp:TextBox ID="txtTester" runat="server" CssClass="Hide"></asp:TextBox>
Note: you can't use validation with the Hidden
control