HI

How I generate Meassage once my array is full?

Thanks
Tank50

Dani AI

Generated

Quick summary and a reliable fix.

This symptom (Next button only enabling after extra clicks) usually means the collection you expect to grow is being reset or the enable-check runs at the wrong time. described the UI flow and pointed toward using the collection size; below are concise checks and a simple pattern that fixes the common causes.

Common causes to check

  • The list is re-created on every postback/page load instead of being preserved between requests.
  • The add/check order is wrong: the code verifies size before the new item is added.
  • The code is updating a different list instance than the one the UI uses.
  • A later step (data binding, validation, page lifecycle code) is disabling the button after you enable it.

A simple, safe pattern (ASP.NET WebForms example)

  • Persist the list between postbacks (Session or similar).
  • Add the new Employee, save the list back, then immediately check the count and set btnNext.Enabled using >= against the user-selected target.

Example C# save-handler:

protected void btnSave_Click(object sender, EventArgs e)
{
    var employees = Session["Employees"] as List<Employee> ?? new List<Employee>();
    employees.Add(new Employee { Name = txtName.Text, Address = txtAddress.Text });
    Session["Employees"] = employees;

    int required = int.Parse(ddlCount.SelectedValue);
    btnNext.Enabled = (employees.Count >= required);
}

Troubleshooting tips

  • Put a breakpoint or log the list count inside the save handler to confirm when items are added.
  • Ensure any list initialization in Page_Load is wrapped in if (!IsPostBack) so you do not wipe stored items.
  • For guidance on the API and page lifecycle, see the docs for List<T>.Count and Page.IsPostBack.

If the app is not WebForms, apply the same principles: persist the collection across user actions, add before you check, and verify no other code resets the button state.

Recommended Answers

All 4 Replies

Every array is full of initial values or nulls. Do you want to show a message when array index reaches out of limit?

HI
Thanks adatapost for ur reply.By mistake I post this question two time.Please refer to second one.

Thanks
Tank50

Hi
Ancient Dragon delete my original post,Anyway I have to write my question here again.

I have List and I used save employee objects into list,first user has to select how many employee objects save in list.Assume user select 2 employee obejcts,so user has to enter employee details (Name,Address,etc..) once he fill the details then he has to clcik on save button to add the employee object into list.In one time user can add onlyone employee object .There is anotehr button called"Next Page" ,but its disable.So once user add second object into list then "Next Page" button should enable.

I wrote coding for that part,but its only works when user clcik on the save button in thrid time.Howdo I do this?pelase help me slove this problem.

Thanks
Tank50

Your question is a bit hazy but I think you mean something like :
If MyList.Count is equal to 2, then enable my next button.
A List can not easily get "full" as it expands itself automatically when needed.
An array will give an index out of range error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.