Sunday, 15 June 2014

asp.net - Loop through programmatically added html in literal control -



asp.net - Loop through programmatically added html in literal control -

i wondering if there way loop through html checkboxes have added in literal codebehind.

i have tried:

protected sub splitpdfpagesbutton_click(sender object, e eventargs) handles splitpdfpagesbutton.click dim integer = 0 each c command in page.controls if typeof c htmlinputcheckbox dim cb htmlinputcheckbox = directcast(c, htmlinputcheckbox) if cb.checked = true += 1 end if end if next msgbox(i) end sub

but think problem loop finds literal container(?).

the reason doing because don't know how many checkboxes generated before runtime.

this code far (as notice commented out section, have tried adding asp.net controls , replacing htmlinputcheckbox snippet above checkbox):

for each fil fileinfo in allfiles '########################################################## 'add image controls 'dim hl new hyperlink 'hl.id = pagecount 'hl.cssclass = "preview" 'hl.navigateurl = "xxx" 'hl.imageurl = "xxx" 'hl.width = 20% 'hl.height = 20% 'form1.controls.add(hl) 'form1.controls.add(new literalcontrol("<br />")) ''add checkboxes 'dim chb new checkbox 'chb.id = pagecount 'chb.text = "break here" 'dim lb new label 'lb.text = "page #" & pagecount 'form1.controls.add(lb) 'form1.controls.add(chb) 'form1.controls.add(new literalcontrol("<br />")) 'pagecount += 1 '############################################################ str '.appendline("<img src=""xxx"" style=""width:50%; height:50%""/><br />") .appendline("<b>page #: " & pagecount & "</b>") .appendline("<div class=""leavespace""></div>") .appendline("<a href=""xxx"" & """ class=""preview""><img src=""xxx & """ style=""width:20%; height:20%;""/></a><br />") '.appendline(environment.newline) .appendline("-------------------<br />") .appendline("<input type=""checkbox"" value=" & pagecount & ">break here</input><br />") .appendline("-------------------<br />") .appendline("<div class=""leavespace""></div>") '.appendline(environment.newline) end pagecount += 1 next str.appendline("</div>") literal1.text = str.tostring

in general way to @ regular html elements code behind add together attribute runat="server", not believe possible within asp.net literal control, literal used represent static elements , text on page. may not right though.

take @ this: http://msdn.microsoft.com/en-us/library/system.web.ui.literalcontrol(v=vs.110).aspx

html asp.net vb.net

No comments:

Post a Comment