开发者

How to Findcontrol when we use literal to create it

I am using a panel and then I create a literal in it, than I create :

string temp ="
<input type="checkbox" id="forum0">
<input type="checkbox" id="forum1">
<input type="checkbox" id="forum2">
<input type="checkbox" id="forum3">
<input type="checkbox" id="forum4">
<input type="checkbox" id="forum5">
" ...

and then assign this sting to

literal.text=temp;

now if i want to find the checkbox with id=forum0 ho do i do that i am using findcontro开发者_JAVA技巧l i have used almost everything kindly help with example.

thank you


If you're adding form elements to your form by using literal controls, you can't get these controls by FindControl method. Because they're added to your page as static html elements.

You have two options to reach them at server side :

  1. You should add them as server control. Then you can perfectly access them.
  2. If you only want to access their values when your page posts back, you can use Request :

    string yourControlsValue = Request["Your_Controls_Name"];


ASP.Net will only instantiate control objects for the controls found on the aspx page, not that are delivered through the actual rendered HTML, which is where your checkbox is being created. You should find a parameter being returned to the Page handler with the name 'forum0' and that should be accessible through the Request["forum0"] construct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜