473,804 Members | 3,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Autopostback, binding and losing selection

Hi-

I'm a bit rusty cause it's been awhile since I've made an asp.net app, but
here is what I want to do:

single aspx page
bound DropDownList w/ autopost back that holds names of customers
DataGrid that shows customer data

When a user selects a customer from the drop down, I get the selected
value(customer ID) and store it into a member variable (mCustId) then I call
my BindData() method that uses that CustId to filter a DataTable and show
the correct data for that customer.

Everything works except when the Autopostback fires, I don't have the
correct selection in the DropDownList. This is because I'm calling
BindData() which also binds the DropDownList.

The problem is obvious and a basic solution is also obvious (call separate
function just to bind the grid) but this does not seem like a very flexible
solution. Is there some way to make the DropDownList's selectedItem value
persist?

Based on what I have described here(this MUST be a common approach) what is
the standard way to handle this?

Thanks for any tips or help!
Steve
Nov 18 '05 #1
2 1623
There is no way to do like your describing.
You should not bind again the dropdownlist in the postback event.

I'm a bit rusty cause it's been awhile since I've made an asp.net app, but
here is what I want to do:

single aspx page
bound DropDownList w/ autopost back that holds names of customers
DataGrid that shows customer data

When a user selects a customer from the drop down, I get the selected
value(customer ID) and store it into a member variable (mCustId) then I call my BindData() method that uses that CustId to filter a DataTable and show
the correct data for that customer.

Everything works except when the Autopostback fires, I don't have the
correct selection in the DropDownList. This is because I'm calling
BindData() which also binds the DropDownList.

The problem is obvious and a basic solution is also obvious (call separate
function just to bind the grid) but this does not seem like a very flexible solution. Is there some way to make the DropDownList's selectedItem value
persist?

Based on what I have described here(this MUST be a common approach) what is the standard way to handle this?

Thanks for any tips or help!
Steve

Nov 18 '05 #2
OK, thanks for the response. Atleast I know I'm not missing anything now ;)
"SHENG333" <wh********@unt soft.com.cn> wrote in message
news:ea******** ******@TK2MSFTN GP12.phx.gbl...
There is no way to do like your describing.
You should not bind again the dropdownlist in the postback event.

I'm a bit rusty cause it's been awhile since I've made an asp.net app, but here is what I want to do:

single aspx page
bound DropDownList w/ autopost back that holds names of customers
DataGrid that shows customer data

When a user selects a customer from the drop down, I get the selected
value(customer ID) and store it into a member variable (mCustId) then I

call
my BindData() method that uses that CustId to filter a DataTable and show the correct data for that customer.

Everything works except when the Autopostback fires, I don't have the
correct selection in the DropDownList. This is because I'm calling
BindData() which also binds the DropDownList.

The problem is obvious and a basic solution is also obvious (call separate function just to bind the grid) but this does not seem like a very

flexible
solution. Is there some way to make the DropDownList's selectedItem value persist?

Based on what I have described here(this MUST be a common approach) what

is
the standard way to handle this?

Thanks for any tips or help!
Steve


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1857
by: Null | last post by:
Hello -- Is there a way to prevent the autopostback of a drop down list if there is a "default" item in the list -- example, a drop down list where the first item says "Select One" and the remaining items are all values available for selection....if the user changes the selection I want to postback, unless they are selecting the default item. Is there a way to do this using autopostback? Or should I just use client side script and...
3
3065
by: Lloyd Sheen | last post by:
I have a page that works fine. I am trying to optimize the page by overriding some of the Information that is being saved in the hidden VIEWSTATE. If I make the properties of the dropdown False for ViewState and True for AutoPostBack, it does reload the page but does not call the SelectedIndexChanged event. If I put the ViewState to True then it is called. Does this mean that I cannot get that event and deal with it in better code
8
9367
by: Matthew Louden | last post by:
why need to set autopostback property to be true?? I know autopostback event means to send the form to the server automatically. I tried checkbox, checkbox list, radio button, and radio button list, and they all need to set autopostback property to be true, in order to make the event of the control fires. I know this is the must, but I dont know why. Please advise! Thanks!
0
1156
by: Jaleel Syed via .NET 247 | last post by:
Hi, I have a Search page, which has a Search Button which whenclicked, Binds a DataGrid to the Data returned from Search(whichimplies that I am not Binding the Grid in Page_Load method). Inthe EditTemplate, I have a DropDownList with AutopostBack Trueand I have also defined a SelectIndexChanged event Handler forit. Along with the DropDownList, I also have a two ListBoxes andAdd and Remove Buttons. The first ListBox should be filleddepending...
5
1816
by: Mani | last post by:
Hi, Is there any other way to quickly grab the selected index/value of a dropdownlist other using than the autopostback property to true? ... I found the autopostback to slow down things.... in classic asp, there used to be request.form("<<name of a hidden value>>") ..... thanks in advance
3
1350
by: Tina | last post by:
I have a grid with a select button. I went to turn off AutoPostBack and there is no such attribute. Is there any way to make a grid behave as would a listbox and not autopost back upon the selection? Thanks, T
2
5503
by: rdb | last post by:
VB.NET web program with a webform w/2 dropdownlistboxes, set to AutoPostBack TRUE, selection in either dropdown fires the SelectedIndexChanged events correctly UNTIL I navigate to second webform in the same project, THEN use the Back button to return to first webform; then changing the selection of the second dropdownlistbox fires the SelectedIndexChanged event for the FIRST dropdownlistbox. I realize that a) using an eventhandler for...
3
978
by: trialproduct2004 | last post by:
hi all i am new to asp.net can some one tell me use of autopostback of dropdownlist. When i set this property to true my selectionchanged event is getting fired. but when this property is set to false then event is not getting raised. why this is happening. please help me. Thanks in advance.
1
2720
by: pleaseexplaintome | last post by:
I have a datagrid with checkboxes and I can check/uncheck the checkboxes to update a database by calling my oncheckchanged function. I would like to add popup asking the users if they are sure they want to proceed. I have written a javascript function named confirm_duplicate and it works as expected - it checks/unchecks checkboxes depending on user response.
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.