简体   繁体   中英

How to take or check the value from Dynamic Generated HTML CheckBox on Aspx.vb Code Behind

I am using Html Check Box that is generated dynamically on the page.

<input type='checkbox' id='chk_"+kDyn+"' name='chk_"+kDyn+"' value='"+0+"' checked />

When I tried to get the value from checkbox it always returns 0 even if, it is checked or not checked

on Code Behind I am trying it as

ChkInsStatus=Convert.ToInt32(Request.Form("chk_" & intCounter))
IF  ChkInsStatus = 0 Then                   
    Response.Write("  got  ")
else
    Response.Write("  not  ")
End If

it always prints got.. even if I checked the check box or unchecked it.. how to do it I am using aspx vb

That's because the value is not an Int32 and always returns default 0. If the checkbox were checked then it returns the value else returns null.So you can get it's value like this:

chkValue = Request.Form("chk_" & intCounter)
IF  chkValue <> NULL Then                   
   Response.Write("The value is:" & ChkInsStatus)
Else
   Response.Write("The value is not selected.")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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