Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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:
Code:
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
        {
            if(selectedvalue=="ResistantL")
            {
                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.DataValueField="re_MLNO";
                    mlno_DDL.DataTextField = "re_MLNO";
                    mlno_DDL.DataBind();
                    resultsLabel.Visible= true;
                    mlno_DDL.Items.Insert(0, "ANY");
                }
                connection.Close();
            }
        }
        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(Specific_Query_DDL.SelectedItem.Value=="ResistantL")
            {
                if(mlno_DDL.SelectedItem.Value=="ANY")  //All the values from the Db are pulled if ANY is chosen from the second DDL
                {
                    executeResistantListQuery_ANY();
                }    
                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
                {
                    executeResistantListQuery_MLNO(mlno_DDL.SelectedItem.Value);
                }
            }

        }
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..
 
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
Default

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
VbKnowledgebase.com
The Following User Says Thank You to pons_saravanan For This Useful Post:
skhan (September 1st, 2009)
 
Old September 1st, 2009, 09:10 AM
Authorized User
 
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
Default

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




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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.