在codebehind C#访问HTML文本框和标签数据 [英] Accessing html textbox and label data in codebehind c#
问题描述
荫使用mysite的HTML控件(。我不希望用asp控制).problem这里我'无法获得codebehind C#的标签和文本数据
他是我的HTML控件
Iam using html control in mysite (idon't want to use asp controls).problem here i'am unable to get the data in label and textbox in codebehind c# he is my html controls
<form runat="server" class="sainex_form1">
<input id="txtDateTime" runat="server" value="" type="text" datetime="datetime" />
<label id="lblJobCity" runat="server">
</form>
<p class="button-row">
<input class="btn-submit" runat="server" type="image" name="image" id="Image4" onclick="UpdateActivity()" />
</p>
在updateActivity()我使用发送值到C#的jQuery AJAX
in updateActivity() i'm sending values to c# using jquery AJAX
和在C#中使用这种code IM
and im using this code in C#
有关文本框:
string a=txtDateTime.Value;
有关标签:
string b=lblJobCity.InnerText;
从上面我得到空值,我也尝试
from above to i'm getting empty value and i also tried
Request.Form["lblJobCity"].ToString();
但没有任何结果PLZ建议我对这个
but no result plz suggest me on this
推荐答案
不要放一些数值的控制:例如
Do put some values in the controls: E.g.
<input id="txtDateTime" runat="server" value="2014-12-12" type="text" datetime="datetime"/>
<label id="lblJobCity" runat="server">Some Text goes here </label>
然后 txtDateTime.Value
和 lblJobCity.InnerText
将提供数据的服务器端
Then txtDateTime.Value
and lblJobCity.InnerText
will provide data server-side
的更新的下面是完整的形式,使其工作:
UPDATE Here's complete form to make it work:
<form id="form1" runat="server">
<input id="txtDateTime" runat="server" value="" type="text" datetime="datetime" />
<label id="lblJobCity" runat="server">Seattle</label>
<input type="submit" id="submit" runat="server" onserverclick="submit_ServerClick" />
</form>
,然后检查事件的值:
And then check the values in the event:
protected void submit_ServerClick(object sender, EventArgs e)
{
string a = txtDateTime.Value;
string b = lblJobCity.InnerText;
}
这篇关于在codebehind C#访问HTML文本框和标签数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!