.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

DropDownLists and AutoPostBack

Posted By:      Posted Date: August 29, 2010    Points: 0   Category :ASP.Net
Hi,I have a web form with a number of DropDownLists on. The selection in each determines what data is displayed in the other lists, all of which data comes from a SQL server table. I've noticed that when I set AutoPostBack to true, the whole page refreshes when changing the selection within each list and I've also noticed that the values selected in the other lists are lost.Is there anyway which I can:1) Maintain values already selected across postbacks2) Stop the page refreshing each time a new item is selectedThanks in advance,Kev

View Complete Post

More Related Resource Links

GridView EditTemplate DropDownLists' Loads fire before SelectedIndexChanged events on AutoPostBack=

My GridView allows EditTemplate but no DataSource in the aspx page. I set the DataSource & DataBind in code behind. My problem is with 2 of the 4 DropDownLists: they require AutoPostBack=true b/c the load of ddlDptmtGrid is dependant on the selection from ddlOrgGrid, and the load of ddlPosGrid is dependant on the selection from ddlDptmtGrid. The problem lies in that every postback calls each ddl's load & then the SelectedIndexChanged event, by this point the SelectedValue has been reset or wiped. And i can't use "if (!IsPostBack) { }" b/c the initial click of the lnkEditBtn is a postback & the DropDownLists don't even exist till in Edit Mode, so i need this initial load. But it appears on every postback all the controls in Edit mode are wiped & re-initialized, so it forces each DDL to be re-declared & re-loaded, but then the SelectedValue (which caused the postback) cannot be remembered?<asp:GridView ID="gridPendRoles" runat="server" CellPadding="5" AutoGenerateColumns="False" BackColor="#CCFFFF" BorderColor="Black" BorderStyle="Solid" onrowdeleting="gridPendRoles_RowDeleting" onrowediting="gridPendRoles_RowEditing" onrowcancelingedit="gridPendRoles_RowCancelingEdit" onrowupdating="gridPendRoles_RowUpdating"

listview 3.5 bind dropdownlists edit item template VB.NET


I am trying to do this with many issues of data binding doubling the amount and not setting selectedValue on dropdownlist. I have read some posts and they help but I am missing a crucial piece. My problem is that my dropdownlist is doubling the amount of records for the dropdownlist. Instead of "YES;NO;SELECT A VALUE", I am getting "YES;NO;SELECT A VALUE;YES;NO;YES;NO". My database is correct with the UPDATE part but the rebind after update is failing horribly.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            If Session("ACTIVETAB").ToString() = Session("SUBCONTRACTSATABNO").ToString() Then
            End If
        End If
    End Sub

    Public Function loadlookups(ByVal id As String, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) As DataTable
        Select Case id
            Case "ddlCertReceived"
                dt = GetLookupTable("SubcontractsA", "Sub 1 Cert Received")
                Dim ddlCertReceived As DropDownList = _
                CType(e.Item.FindControl("ddlCertReceived"), DropDownList)
                ddlCertReceived.DataSource = dt
                ddlCertReceived.DataTextField = "lup_text"

2 Databound Dropdownlists... how to bound data to the 2nd one?


hi there,
I have a database with the following table:

Table Job {
    nvarchar(50) JobID,
    nnarchar(50) JobName,
    Bit/Bool     Active;

I'm trying to build an .aspx page with two dropdownlists:

  1. The first will display the JobIDs of all Jobs available in the Database (I have done this part and it's working)
  2. The second will display by default the value "Choose Job first".

  What I'm trying to do is: Once the user chooses the JobID (step 1), the page should reload and the 2nd dropdownlist should display the following:

  •  if the value of the field "Active" of the corresponding JobID is '1'(i.e, the Job is already active) -> then the Dropdownlist should display "Already active" and "Deactivate" values
  • if the value of the field "Active" of the corresponding JobID is '0'(i.e, the Job is inactive) -> then the Dropdownlist should display "Activate" and "Already Deactive" values.

This is my code:


<div class="formField JobSelect">
<asp:Label ID="lbl_J

AutoPostback in Repeater in UpdatePanel is refreshing the page

Here's quite a weird problem:I've got a TextBox with AutoPostBack="true" and OnTextChanged property set.The textbox is located inside a Repeater, which in turn is located inside an UpdatePanel.Problem is - whenever the TextBox postsback, the whole page gets reloaded, instead of the UpdatePanel only.Here's how the thing looks:<asp:UpdatePanel runat="server"> <ContentTemplate> <asp:Repeater ID="itemsRepeater" runat="server"> <HeaderTemplate> <ul class="lstProducts"> </HeaderTemplate> <ItemTemplate> <li> <asp:TextBox AutoPostBack="true" OnTextChanged="whatever_Click" runat="server" /> </li> </ItemTemplate> <FooterTemplate> </ul> </FooterTemplate> </asp:Repeater> </div> </ContentTemplate> </asp:UpdatePanel> Interesting thing is, if I take the TextBox out of the repeater, it refreshes only the UpdatePanel.So is if I put a Button inside the repeater - only the UpdatePanel gets refreshed.But whenver I place an AutoPostBack-ing control inside the Repeater, the whole page gets refreshed.Any help would be welcomed,Thanks<asp:UpdatePanel runat="server">             &

Using Update Panel on a repeater using Dropdown Autopostback

 Hi, The subject is explanatory, but here are some details:   I want to update a repeater when SelectedIndex value changes for a dropdown list. The problem is Nothing happens. My aspx page is present in a nested master page. and neither autopostback works nor update panel. i have set the AsyncPostBack trigger on SelectedIndexChange event.   Please let me know what am i doing wrong or what am i missing. PS: I have never worked on ajax before so I might have overlooked something.

disable autopostback of checkbox inside of GridView during SelectedIndexChanged of ListView

Hi, I hope my question is clear: I have a checkbox placed inside a gridview: <GridView><asp:TemplateField HeaderText="Driver">   <ItemTemplate>       <asp:CheckBox ID="CheckBoxDriver" AutoPostBack="true" OnCheckedChanged="GridView_Persons_SelectedIndexChanged" ValidationGroup='<%# Eval("ID") + "-" +((GridViewRow)Container).RowIndex %>' CssClass="CXDriver" runat="server" Checked='false' />   </ItemTemplate>       </GridView> For example: A listViewItem 1 has 3 drivers are checked, A listViewItem 2 has 2 drivers are checked. Therefore, if changing the selectedIndex of the list, the checkbox indexChanged event will be fired. How could I disable the autopostback of the checkbox during the listview item changed. Thanks in advance

Autopostback on the last list in a Cascading drop down list series

Hi,First off I'm very new to Ajax for .NET.  I have a Cascading drop down list that is working fine to load the correct lists however I would like to have the last one initiate a query and display a datagrid on the same page containing the results of the query.  Without Ajax involved this seems rather easy by using autopostback on the drop downs.  If I could do it through Ajax that would be great but I can settle with having the page to reload to display the data.  Right now I'm not sure how to do either.  I enabled autopostback on the last drop down and wrote a method for it but I get an error at runtime saying:Invalid postback or callback argument So I'm really not sure what to do to get this to work right.Any help would be appreciated.Thanks,-Jordan

LoginView, DropDownList, Cookie, AutoPostBack Conundrum

OK, I am at a complete loss. Users for my site can have many stores to configure under their one user account. When they login I have the app generate a cookie for each store and hold all the stores basic information. For each cookie I then generate a list item in a drop down list. I can get the list to generate just fine and all of the pages that reference the list get the information fine. When I change the list to a different item however, and the page posts back my first LoginView is set to LoggedInTemplate while my navigation loginview (in site.maser like the first one) and my content loginview (in the actual page) come back in AnonymousTemplate, even though the user is authenticated. I can either do a response.redirect or physically refresh the page and all loginviews are in LoggedInTemplate again. The problem is though that I lost all of the postback data so I can essentially only view information on the first item in the dropdownlist. Now, I am new to asp.net authentication, and while I feel that I am starting to get the hang of it, there is a very good chance that I am doing something wrong. I have all the authentication working correctly and except for this postback issue. I can login, navigate through pages that aren't accessible without being authenticated and I can logout without issue. If anyone has any suggestions it would be gr

Cascading DropDownLists in DetailsView

Hi guys,My first post ;]I am a beginner in asp.net and therefore, cause problems that for me seem unsolvable.I hope someone can help me resolve this. Thank you.Here is the case:I use Visual Studio 2008 ASP.NET 3.5I have a DetailsView control with several fields that is in insert mode. Three of them are the source of my problems and headaches.I have three DropDownLists in template fields.The first one is OK, bound to it's designated field in table1 in the database. The next two however have to change their bound tables according to the SelectedValue. So far, I've managed to get it working, BUT when I insert the data I've entered, these two DropDownLists are not entered into the database.DropDownList3 - the list that controls the other two DDLsDropDownList4 and DropDownList5 - the list that need to change their items accordinglyDropDownList3 has six different values, so I have 6 tables for each of the other two DDLs However I have only tried with one to see if it would work, that's why the Sub seems incomplete.Here is the relevant part of the code: <asp:TemplateField HeaderText="Category" SortExpression="category"> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("category") %>'></asp:T

requiredfieldvalidator and AutoPostBack howto

Fairly new to ASP NET. I have 3 text boxes all with AutoPostBack set , in the example below the textchange events don't do anything although in reality they will. I have required field validators on each. All text boxes are initially blank. I would have assumed that if I tab out the first text box without entering something I would get an error message but not so. If I enter something tab out and back in and delete the text then I get either With CausesValidation="False" a message that flashes and disappears With CausesValidation="True"  I get all the error messages. Is it possible to get required field messages only for the textbox you have just left empty. I have spent quite a long time on this to no avail. Thanks Jim<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication11.WebForm1" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <asp:ToolkitScriptManager

Dropdownlist not firing SelectedIndexChanged on first item with autopostback true

Hi: Has anyone ever found a work around for the well documented and well known bug, the dropdownlist bug? Specifically where the SelectedIndexChange event does not fire on the first listitem, althought both autopostback and enableviewstate are true? In other words, if the first three items in the dropdownlist are red, blue, green, if you select green, the SelectedIndexChanged will fire, but if you then select red, the first item in the ddl, the event will not fire. All listitems will fire the SelectedIndexChanged event, except for the very first listitem. The HACK has always been to include a dummy item as the first list time like"Select a Color" to get around the first item bug. I have got a situation where I cannot use that hack. Ideas?  TIA, Bill  

Gridview, MasterPage, Ajax, AutoPostback and FRUSTRATION

I have a peice of code for a custom Gridview that works great if it is not in my Master.Page. As soon as I put it in my masterpage /ajax update panel it seems the autopostback function of my checkbox stops working.... please advice. Here is the relevent code :   NOTE: (I have tried to turn on ViewState in every thing I could think of.....still nothing) <asp:GridView ID="gvHR" CssClass="gridview" runat="server" AllowPaging="True" EnableViewState="true" DataKeyNames="HRID" AutoGenerateColumns="False" DataSourceID="ldsHR"> <Columns> <asp:BoundField DataField="FirstName" HeaderText="FirstName" ReadOnly="True" SortExpression="FirstName" /> <asp:BoundField DataField="LastName" HeaderText="LastName" ReadOnly="True" SortExpression="LastName" /> <asp:BoundField DataField="EmailName" HeaderText="EmailName" ReadOnly="True" SortExpression="EmailName" /> <asp:TemplateField HeaderText="LeftCompany" SortExpression="LeftCompany&quo

Weird behaviour of Gridview with textbox with autopostback OnTextChanged and AJAX CalendarExtender

I ran in to some strange behaviour of Gridview with textbox with autopostback OnTextChanged and AJAX CalendarExtender. This gridview is in an updatepanel with scriptmanager. When my gridview is filled with data, it keeps running my OnTextChanged  function and therefor makes my application terribly slow. I need to have the autopostback and ontextchanged function to recalculate stuff in my gridview. Does anybody know of this problem and if so does anybody found a workarround ?

autopostback problem in gridview why it show multiples times...


    <form id="form1" runat="server">
        <asp:DropDownList ID="DropDownList9" runat="server" DataSourceID="SC" DataTextField="ItemNo"
            DataValueField="ItemNo" Style=" left: 131px; position: absolute;
            top: 41px; z-index: 104;" OnSelectedIndexChanged="DropDownList9_SelectedIndexChanged" TabIndex="12" AutoPostBack="True" OnDataBound="DropDownList9_DataBound">
        <asp:GridView style="Z-INDEX: 101; LEFT: 14px; POSITION: absolute; TOP: 183px; width: 953px;" 
        id="Gridview1" runat="server" Height="127px" ForeColor="Teal" Font-Size="12pt" 
        Font-Names="Palatino Linotype" Font-Bold="True" Visible="False" 
        BorderColor="Transparent" OnRowDataBound="Gridview1_RowDataBound" 
        ShowFooter="True" SelectedIndex="5" OnRowCreated="Gridview1_RowCreated" 
        GridLines="None" CellSpacing="2" AutoGenerateColumns="False"><Columns>
<asp:BoundField DataField="RowNumber

DataType for DropDownLists, ListBox, CheckBoxes and RadioButtons



When using a DropDownList, ListBox, CheckBoxes, RadioButtons what data type do you suggest to hold the values?

Usually the values are 1, 2, 3, etc. It makes more sense to me and usually these are the id's of the items.

I tend to use the following:

1) When only ONE option can be selected I amke the property of type INT? (Nullable int).

    This is for when no item is selected it makes more sense to me to check if it's null then 0. 

    And in most validation frameworks there is a null validator.

2) If MANY options can be selected then I use INT[].

    Then I can check for null or count the selections.

What do you think?



How to change from button post back to autopostback

Can anyone help me with how to change from an update button to an autopostback, so that every time the info is changed it will be updated.

<%@ Page language="c#" Inherits="GreetingCardMaker.GreetingCardMaker" CodeFile="NewGreetingCardMaker.aspx.cs" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">
		<title>Greeting Card Maker</title>
		<form runat="server">
			<div style="BORDER-RIGHT: thin ridge; PADDING-RIGHT: 20px; BORDER-TOP: thin ridge; PADDING-LEFT: 20px; FONT-SIZE: x-small; PADDING-BOTTOM: 20px; BORDER-LEFT: thin ridge; WIDTH: 293px; PADDING-TOP: 20px; BORDER-BOTTOM: thin ridge; FONT-FAMILY: Verdana; HEIGHT: 486px; BACKGROUND-COLOR: lightyellow">Choose 
				a background color:<br />
				<asp:DropDownList id="lstBackColor" Height="22px" Width="194px" runat="server">

TextBox AutoPostBack not working when handling other DHTML event


I have to format a number in a TextBox while it is being typed. Right after the TextBox looses focus, I need to do other processing on server side, including some database queries.

I'm doing the formatting by handling the onkeyup event, client side. But when I add the handler, the onTextChanged event stops firing on the server. I've tried different return values for the handler but unfortunatelly I'm stuck.

To reproduce the problem, here is a sample where the formatting function was replaced by a simple "convert to uppercase" function. You'll see that, contrary to the expected, the Label doesn't get filled when the TextBox looses focus. It does get filled, however, if the user presses the ENTER key.

What can I possibly be doing wrong with such a simple task?


<%@ Page Language="VB" %>

<script language="VB" runat="server">

Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)

'' Adding the event handler like this has the same effect as adding it inline

'txtTextBox.Attributes.Add("onkeyup", "return(upperCase(this));")

End Sub

Protected Sub txtTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)

lblTextBox.Text = S

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend