如何在asp.net代码中获取html标签值 [英] How to get html label value in asp.net code behind

查看:85
本文介绍了如何在asp.net代码中获取html标签值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用html标签和文本框在aspx页面上生成动态控件。

我得到了文本框值但没有标签控件值。我在列名称的基础上使用了标签作为列名,我将值插入datatbase。

这是我的代码...

 < span class =code-keyword><   tr     id   =  ContentPlaceHolder1_hd2 >  
< td > < label id = lbl_2 名称 = lbl_2 text = sfsdfd > 公司< / label > < / td >
< td > ; < 输入 type = text 样式 = width:200px; id = txt_Company2 名称 = txt_Company2 maxlength = 255 = > < / td >
< / tr >



in c#

< pre lang =c#> return Request.Form [controlID];





所以,当我通过文本框控制我d喜欢'txt_Company2'然后返回值,但是当我传递标签ID时,如'lbl_2',它返回null。我调试了c#代码Request.Form,它显示了我所有的文本框ID而不是标签的ID。



注意:我可以'是使用服务器控制,因为它是动态的,所以它在回发后丢失了它的身份。



所以,请建议任何解决方法。

解决方案

你可以在这里使用javascript:

document.getElementById('<%= ID-value.ClientID%>')


Hi,
i am using html label and text box for generating dynamic control on aspx page.
I got the text box values but not label control value. i used label for column name on the bases of column name i insert value into datatbase.
Here is my code...

<tr id="ContentPlaceHolder1_hd2">
		<td><label id="lbl_2" name="lbl_2" text="sfsdfd">Company</label></td>
		<td><input type="text" style="width:200px;" id="txt_Company2" name="txt_Company2" maxlength="255" "=""></td>
	</tr>


in c#

return Request.Form[controlID];



so, that when i pass the text box control id like 'txt_Company2' then is returns the value but while i pass the label id like 'lbl_2' it returns null. i debugs the c# code "Request.Form" it shows me all text box ID's but not label's ID.

Note: I can't be use server control because it is dynamic so it lost its identity after postback.

So, please suggest any work around.

解决方案

You can use javascript here like:
document.getElementById('<%=ID-value.ClientID%>')


这篇关于如何在asp.net代码中获取html标签值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆