views:

193

answers:

3

I know there is a similar problem on this forum, but the solutions did not really work for me. I am populating form controls with fields from a few different data sources, and the data shows up great.

I have an ImageButton controlwhich has an OnClick Event set to grab all of the data from the form. Unfortunately, when I click the button, it seems as though the page is reloading first, and THEN is executes the OnClick call. The data that was hand-entered, or hard-coded seems to be pulled fine from the controls it was entered in, but anything that was pulled from a datasource is not able to be read. Any ideas. this is the last hurdle in a project that I have been working on for 6 months. I want to go home...

Thank you so much in advance.

Jason

A: 

Are you talking about drop downs or gridviews? When are you binding data, on page load?

Good design will have you bind your data upon page load but only in

if(!isPostBack){
    dropdown.databind()
    gridview.databind()
}.

Otherwise it will rebind every page load. If its not reloading you can get selected values from those controls if thats what your looking for.

An alternative is to set your data source and databind in your aspx page with a datasource object. That automates the above automatically.

Cptcecil
A: 

Actually, it is hiddenfields, dropdowns, labels, and textfields. I just tried doing the binding in the init, and the load, but no dice. When I tried binding it on !isPostBack only, none of the fields showed up.

I think one of the main problems is that the dataset I am getting is from a method call to an API. I receive the data fine, but it comes in programmatically, then I have to do all of the control-setting programmatically as well. Would you like to see the code for ideas? Thank you for helping, no one is working today!

Jason

please edit your question instead of posting an answer
Steven A. Lowe
A: 

Have you enabled viewstate on your controls? Posting code samples would go a long way to helping solve your issue.

Chuck