468,457 Members | 1,637 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

Update & Database Access Using IsPostBack

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
4 1556
Plater
7,872 Expert 4TB
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
gihope
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
7,872 Expert 4TB
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
gihope
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.

Similar topics

1 post views Thread by Ray Valenti | last post: by
1 post views Thread by radha | last post: by
4 posts views Thread by René Kabis | last post: by
25 posts views Thread by Neo Geshel | last post: by
1 post views Thread by mursyidatun ismail | last post: by
3 posts views Thread by virlinz | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.