如何使用ASP.NET C#设置html输入类型的文本值? [英] How to set html input type text value using ASP.NET C#?
问题描述
我有一个html控件,我想设置它的值...。
这是控件:
I have an html control which I want to set its value .... here's the control:
<input runat="server" id="first_name_txt" type="text" placeholder="First Name" />
在后面的代码中,我使用:
in code behind, I use:
first_name_txt.Value = String.empty;
但我的输入控件的值仍然具有 blah-blah之类的旧值并且未设置
but the value of my input control still has the old value like "blah-blah" and not set to "".
推荐答案
您好,将数据设置为HTML输入并不是那么容易,但是这里有一个链接可能会帮助您 [链接] 。
1)如果没有用,请尝试设置值,然后通过 JavaScript 对其进行调用,并设置此输入的文本,例如获得的值。
1) If it didn't work up to you try to set a value and calling it through Javascript and set the text of this input like the gotten value.
2)您可以使用runat = server使用[Div]标签,将其清除并创建具有相同ID,名称等的新输入。但是不同的文本值
2) You can use the [Div] tag using runat="server", clear it and create a new input with same id,name,etc. but different Text value
请按以下步骤尝试2(有效):
Try Step 2 as follow(it worked):
<div id="divTitle" runat="server">
<input type="text" class="input_Text" id="Title" name="Title" />
</div>
divTitle.Controls.Clear();
divTitle.InnerHtml = "<input type='text' class='input_Text' id='Title' name='Title' value='" + ds(0)("Title").ToString() + "' />";
其中ds是来自数据库选择查询的数据表
Where ds is a data table that came from select query from database
这篇关于如何使用ASP.NET C#设置html输入类型的文本值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!