简体   繁体   English

在后面的代码中访问html元素

[英]Access html element in code behind

  1. I have created html controls with JQuery.Ajax so I cant have it ID at development time. 我已经使用JQuery.Ajax创建了html控件,因此在开发时无法获得它的ID
  2. I have learned about Request.Form["name"] but it gets elements by name not Id . 我已经了解了Request.Form["name"]但是它通过name而不是Id获取元素。 I need to access elements by id because my controls are radio button and I have got more than one radio button with same name to manage radio grouping. 我需要通过id访问元素,因为我的控件是单选按钮,并且我有多个具有相同name单选按钮来管理单选分组。

What option have I left? 我还剩下什么选择?

Please suggest a solution. 请提出解决方案。

Thanks. 谢谢。

Done it finally..!! 终于做完了.. !!

I used Request["name"] as Amer said that its my final choice. 我使用Request["name"]是因为Amer说这是我的最终选择。 The problem with this approach was that I was using radio button and I had to give same name for radio button to bind them in a single group. 这种方法的问题在于,我正在使用radio按钮,并且必须为单选按钮指定相同的名称,以将它们绑定到一个组中。

like: 喜欢:

<input id="id1" type="radio" name = "groupname" />
<input id="id2" type="radio" name = "groupname" />

Hence I was not getting any value for Request["id1"] or Request["id2"] as this work for name and I was passing id and as name was not unique here I was not able to get the values. 因此,我没有获得Request["id1"]Request["id2"]任何值,因为此工作用于name并且我传递了id并且由于名称不是唯一的,因此我无法获得这些值。 I changed above code to 我将上面的代码更改为

<input id="id1" type="radio" name = "g1" />
<input id="id2" type="radio" name = "g2" />

and for grouping I wrote custom JQuery . 为了分组,我编写了自定义JQuery Now I can get these values using Request["g1"] or Request["g2"] :) 现在,我可以使用Request["g1"]Request["g2"]获得这些值:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM