开发者

On click of a button,obtain the selected value from a checkbox list which is present in a div

开发者 https://www.devze.com 2023-03-21 11:49 出处:网络
I have a aspx page in which there is a div. On click of a button the div is being displayed. The div contains a list of checkboxes and an \"apply\" button. If some values in the list are checked and t

I have a aspx page in which there is a div. On click of a button the div is being displayed. The div contains a list of checkboxes and an "apply" button. If some values in the list are checked and the apply button is clicked, the s开发者_JAVA技巧elected value must be added to the page. This is my requirement. But what happens is that, on click of the "apply" button, page load happens and the list of checkboxes is being cleared. Because of this, i am not able identify the selected items. How to solve this issue? Thanks in advance

    private void Page_Load(object sender, System.EventArgs e)
{

int assp=0;
for(int itest=0;itest<chkAvailablelist.Items.Count;itest++)
{
    if(chkAvailablelist.Items[itest].Selected)
        {
            assp=1;
    }
}

In dubug mode, the chkAvailablelist is being shown as empty


Has every single checkbox got a checked = false when checking on the server (after the button click)?

If so you've probably got something in your page_Load() which is clearing them.

But you need to ask yourself; do you actually want the postback to happen or do you need to check them via javascript?

On another note is viewstate enabled?


If the checkboxes don't exist when the page is rendered, does the server know about them when the postback happens? Could clicking the button un-hide the DIV, rather than JS? That way the server would know about them.

OR

If Page_Load is clearing the checkboxes, is it because you aren't checking for page.ispostback?

I'm sorry if these answers are too basic but some of your description sounds like some basic mistakes I know I've made in the past. :)

0

精彩评论

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

关注公众号