Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 31st, 2009, 11:27 AM
Authorized User
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
Default Problem in isPostBack

Dear all,
I am having problem with placing the proper condition inside the postback method. My Dropdown list value is not retaining on page post back. I am trying to do the following:
1. There are 2 dropdown lists in my program.
2. I have two DropDownLists databound on the webform. The autopostback of the first dropdown list control is set to true. The contents of the first dropdown list is hardcoded. The contents of the second depend on the selected item in the first. In other words: The selectedvalue of the first DropDownList is passed as a parameter for the query at the basis of the second DropDownList's datasource. And this works: Whenever I click on an item in the first DropDownList, the dependant items are shown in the second DropDownList.

3. If I click submit then the specific rows from the DB will be pulled based on the values selected from dropdown list 1 and dropdown list 2.

Problem: In the postback method I think all the times the "ANY" MLNO is selected instead of selecting a specific value from the dropdown list 2. And that's why always all the values are pulled from the DB.

The code is as follows:
using System.Data;
private void Page_Load(object sender, System.EventArgs e)
            if (this.IsPostBack)
                 getMLNO(Specific_Query_DDL.SelectedItem.Value);   //This is where I am generating all the values from the DB for the second dropdown list. And as it's getting post back so even if I click submit button then the page gets post back and the selected value for the second dropdown list gets set to the default value, which is ANY
        private void getMLNO(string selectedvalue)      //This is the method where all the MLNOs are generated
                string sql= "SELECT re_MLNO, MAX(re_SpecimenDate)-MIN(re_SpecimenDate) AS DaysSeronegative FROM ml_hiv_status WHERE (re_HIV1_Status=0) GROUP BY re_MLNO";
                OleDbConnection connection = new OleDbConnection(HIV.Database.DataConstants.CONNECTION_STRING);
                OleDbDataAdapter adapter = new OleDbDataAdapter();
                OleDbCommand command = new OleDbCommand(sql, connection);
                DataSet ds = new DataSet();
                adapter.SelectCommand = command;

                if (adapter.Fill(ds) > 0)
                    DataView view = ds.Tables[0].DefaultView;
                    mlno_DDL.DataSource = view;
                    mlno_DDL.DataTextField = "re_MLNO";
                    resultsLabel.Visible= true;
                    mlno_DDL.Items.Insert(0, "ANY");
        private void mlno_DDL_SelectedIndexChanged(object sender, System.EventArgs e)
        private void submitButton_Click(object sender, System.EventArgs e) //SubmitButton_Click method fetches all the data from the Database depending on the 2 values selected from the 2 dropdown list
                if(mlno_DDL.SelectedItem.Value=="ANY")  //All the values from the Db are pulled if ANY is chosen from the second DDL
                else if(mlno_DDL.SelectedItem.Value!="ANY")  //Data are pulled if a specific MLNO is chosen from the DB, and this one is not working as always ANY value is chosen from the postback method

Thank you all who will try to solve the problem. To me it seems that the the second dropdown list is getting refreshed everytime I am posting the page back/submit and that's why "ANY" is getting selected and thus it's pulling all the data.

Last edited by skhan; August 31st, 2009 at 02:50 PM..
  #2 (permalink)  
Old September 1st, 2009, 02:10 AM
Authorized User
Points: 198, Level: 3
Points: 198, Level: 3 Points: 198, Level: 3 Points: 198, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2008
Location: singapore, singapore, Singapore.
Posts: 54
Thanks: 0
Thanked 4 Times in 4 Posts

you have to change the page_load if condition to Not Postback
and call the second dropdown list binding method in first dropdownlists selected index changed event
Pon Saravanan
The Following User Says Thank You to pons_saravanan For This Useful Post:
skhan (September 1st, 2009)
  #3 (permalink)  
Old September 1st, 2009, 09:10 AM
Authorized User
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts

Thank you! I have done that last night and it's working now. Thanks a lot for your help. :)

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
what is isPostBack amin_pucit ASP.NET 1.x and 2.0 Application Design 2 October 9th, 2013 06:30 AM
WebUserControl IsPostBack == true, always elmemo ASP.NET 2.0 Professional 4 May 4th, 2007 05:09 PM
IsPostBack lamdog ASP.NET 1.0 and 1.1 Basics 1 March 30th, 2005 10:42 AM
IsPostBack() swastikagaur ASP.NET 1.0 and 1.1 Basics 3 March 18th, 2005 09:12 AM
IsPostback executed twice amantona ASP.NET 1.0 and 1.1 Professional 3 February 3rd, 2005 08:41 AM

All times are GMT -4. The time now is 11:38 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.