开发者

accessing HtmlTable inside a placeHolder

开发者 https://www.devze.com 2023-01-27 12:04 出处:网络
I\'m working with a website written in aspx.net over vb. I have a placeHolder, and I create a table of names inside this PlaceHolder, each name has an HtmlInputCheckBox next to it.

I'm working with a website written in aspx.net over vb. I have a placeHolder, and I create a table of names inside this PlaceHolder, each name has an HtmlInputCheckBox next to it. Im doing this in the aspx.vb file, when the page is uploading. Then, when the user wants to send mail, he presses a button and than I need to access the checkboxes, and I'm having problems with this, the S开发者_运维知识库ub doesn't know the checkBox object.

I would love for some help, Thank you!


I understand that you're creating those checkboxes dynamically?

In such case, store them as global member of the class, most simple way is to have List of them:

List<HtmlInputCheckBox> arrCheckboxes = new List<HtmlInputCheckBox>();
...
...
HtmlInputCheckBox myCheckbox = new HtmlInputCheckBox();
arrCheckboxes.Add(myCheckbox);
...

This is C# but should be easy to translate to VB - anyhow having this, you can access the List and it should work.

Worst case as "last resort" you can simply iterate the whole Request.Form collection and look for Keys with name matching to the checkbox name.


Put this in the procedure...

    Dim chkValue1 As New CheckBox
    Dim chkValue2 As New CheckBox

    'Find the Checkbox Controls in the PlaceHolder and cast them to the checkboxes we just made.
    chkValue1 = CType(YourPlaceHolder.FindControl("Checkbox1ControlId"), CheckBox)
    chkValue2 = CType(YourPlaceHolder.FindControl("Checkbox2ControlId"), CheckBox)

    'Now you can do this...
    Dim bolIsValue1Checked As Boolean = chkValue1.Checked
0

精彩评论

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