By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Update & Database Access Using IsPostBack

P: 12
Hi, I have an ASP.NET 2.0 C# issue that has been troubling me for some time, and if someone could shed some light on this I would appreciate it.

This seems to be a commonly themed question, although most relate to DataGrids and this is a slightly different scenario.

This is completely hypothetical, but say I have a form for editing database information.

This form contains two drop down boxes, one of which determines the content of the other. The problem is that in order for the second drop down box to be updated on the autopostback of the first, it needs to be out with the !IsPostback section. However, if I do this then I cannot add it's details to the database when I submit the form using an event handler.

e.g.

if (!IsPostBack)
{
Drop Down List 1 // This has autopostback set so that when I choose a value it populates Drop Down List 2
}

Drop Down List 2 // This is outside the !IsPostback section so updates when Drop Down Box 1 changes, but wont allow the selected value to be updated by the submit event handler.

Event Handler // Submit values to database.

This seems to be caused by the fact that the page is reinitialised before the new values can be entered into the Database. The database therefore is updated with the old values.

I can ensure the second Drop Down Box is updated by including it in the !IsPostBack section but if I do this, then it's value will not obviously be updated when the value of the first Drop Down Box is changed.

Although this is a hypothetical situation, I have had this problem in many different similar scenarios. I want the ability to Edit & Dynamically change! :) Ian
May 23 '07 #1
Share this Question
Share on Google+
4 Replies


Plater
Expert 5K+
P: 7,872
instead ofputting your code in the Page_Load() function, try moxing some into the dropdown1_indexchanged (or some other similar event) function?
May 23 '07 #2

P: 12
That's interesting. So instead of using autopostback, use the index changed event to make a call to the database and potentially databind the second drop down box.

I'm not sure that's possible without refreshing the page, but its worth a try....
May 23 '07 #3

Plater
Expert 5K+
P: 7,872
you would still need the autopostback set.
BUT the data would only be changed on the specific postbacks that relate to the index being changed
May 23 '07 #4

P: 12
Plater I haven't been able to put this into place, because I've been caled off on a development project.

But I wanted to write and say thank you very much for taking the time to consider and reply to my post. Regards, Ian
May 25 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.