Newbie question

  • Thread starter Thread starter Mantorok
  • Start date Start date
M

Mantorok

Hi

I have an ASPX with a member that references a server generated control (in
this case a ListBox).

When the client submits the form I want to check the selected value of the
listbox, however the reference to the generated control returns null.

How can I query the value of the control?

Thanks
Kev
 
Hi Kev,

can you send in your code? Normally you can access the selected value via
ListBox.SelectedValue (the string representation of the selected item),
SelectedItem (the selected item itself) or SelectedIndex (the index of the
selected item in the listbox).

Regards,
Michael
 
To summarise:

As the page loads it gets a suitable control from a generator and then adds
it to a table on the form, when the user clicks the Next button the
mainControl memebr is null?!
private void Page_Load(object sender, System.EventArgs e)

{

// Obtain control for form
mainControl = WebControlGenerator.Get(controller);

tblContent.Rows[0].Cells[0].Controls.Add(mainContr

}

private void btnNext_Click(object sender, EventArgs e)

{

// Try to query mainItem here but returns null

}

HTH

Kev
 
Mantorok,

ah, now I understand, you can't even access the control? The problem here is
that your control was created dynamically and the framework does not have a
mapping for it. If you know the id of the control, you should easily access
it using Page.FindControl().

Regards,
Michael

Mantorok said:
To summarise:

As the page loads it gets a suitable control from a generator and then adds
it to a table on the form, when the user clicks the Next button the
mainControl memebr is null?!
private void Page_Load(object sender, System.EventArgs e)

{

// Obtain control for form
mainControl = WebControlGenerator.Get(controller);

tblContent.Rows[0].Cells[0].Controls.Add(mainContr

}

private void btnNext_Click(object sender, EventArgs e)

{

// Try to query mainItem here but returns null

}

HTH

Kev

Hi Kev,

can you send in your code? Normally you can access the selected value via
ListBox.SelectedValue (the string representation of the selected item),
SelectedItem (the selected item itself) or SelectedIndex (the index of the
selected item in the listbox).

Regards,
Michael
 
Back
Top