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


Post New Web Links

Disabling ViewState for DropDownList and using AutoPostback with SelectedIndexChanged

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :ASP.Net
 

The sites I mantain are using way too much ViewState and I'd like to reduce that so the size of the page is reduced.  I've done a lot to remedy this but I have an issue relating to DropDown lists that use AutoPostbacks.

I have a dropdown list with a lot of list items and a good part of the ViewState usage is to hold the list item data.  If I disable ViewState and set the AutoPostBack property to true, the page will post back and in the page load I am trying to repopulate the dropdown list with cached data.  However, it seems that the SelectedIndexChanged event doesn't fire when EnableViewState="false".

Is it possible to make this work without enabling ViewState for the drodown list?




View Complete Post


More Related Resource Links

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  

Strange connection between ViewState and DropDownList's SelectedIndexChanged event

  

So, I have this code (just for example):


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="Sort by:"></asp:Label>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
            onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem Value="A" Text="A"></asp:ListItem>
            <asp:ListItem Value="B" Text="B"></asp:ListItem>
            <asp:ListItem Value="C" Text="C"></asp:ListItem>
            <asp:ListItem Value="D" Text="D"></asp:ListItem>
        </asp:DropDownList>
        <asp:GridView ID="GridView1" runat="server" onsorting="GridView1_Sorting">
        </asp:GridView>
    </div>
    </form>
</body>
</html>


The Code-behind file looks like that:


public partial class _Default : Syst

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"

disabling element in dropdownlist though visible

  
hey, initially my drop down list shows no items and when clicked it shows the "--select--" item and then a list of items such as apple,orange etc. i want to disable the "--select-- " item so dat it is not selected by user bt should be visible. how to go 4wd wid this????

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

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

Radiobuttonlist SelectedIndexChanged When Changing dropdownlist

  

Hi,

I have a radiobutton list that changes the contents of a dropdownlist when the selected radiobuttonlist index is changed using the SelectedIndexChanged event. Both controls are within the same updatepanel and both have autopostback set to true.

For some reason when I change the dropdownlist and cause a postback, the radiobuttonlist change event fires and repopulates the dropdownlist which effectively cancels the selection made in the dropdown.

I know something simple must be causing this behaviour but I cannot think what and my debugging efforts are not shedding any light thus far. I have tried putting a breakpoint on every procedure in my form and the first event that fires is the radiobuttonlist SelectedIndexChanged event so nothing in my server side code seems to be doing this which suggests it is something in the markup but I can't think what. 

Does anyone have any idea what may be causing this infuriating but obviously simple problem?

Thanks

Andy


Disabling viewstate in master pages

  

Hi,


I have a question regarding disabling viewstate.


I know how to do this in the page, however if I disable in a master page will all child pages and controls be disabled through inheritance?


Thanks in advance


John


Dropdownlist in a repeater firing the SelectedIndexChanged event

  

I have a dropdownlist in a repeater and it's firing the SelectedIndexChanged event but in teh event handler I can not get the dataitem associated with the row that the DDL is in.  Here is the code:


        private void pt_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddl = (DropDownList)sender;
            RepeaterItem ri = (RepeaterItem)ddl.NamingContainer;
            int userdevi

Required Validator disappears after autopostback set to true of a dropdownlist

  

My dropdownlist having data from database added with the following item:

DropDownList.Items.Insert(0, new ListItem("Please select", "0"));

My dropdownlist is inside of updatepanel. The autopostback=true is required.

The code is like following:

<asp:DropDownList ID="DropDownList" AppendDataBoundItems="True" runat="server"
                  DataTextField="Description" DataValueField="CommonCodeId" TabIndex="4" 
                    CssClass="drop_red_style1" AutoPostBack="True" CausesValidation="True" 
                     OnSelectedIndexChanged="DropDownList_SelectedIndexChanged">
                </asp:DropDownList>

<asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server" ControlToValidate="DropDownList"
                    Display="Dynamic" InitialValue="0" SetFocusOnError="true" ValidationGroup="Registration">Required</asp:RequiredFieldValidator>
Please guide me how to keep the required field validator message.


Required Validator disappears after autopostback set to true of a dropdownlist

  

My dropdownlist having data from database added with the following item:

 

DropDownList.Items.Insert(0, new ListItem("Please select", "0"));

 

My dropdownlist is inside of updatepanel. The autopostback=true is required.

The code is like following:

<asp:DropDownList ID="DropDownList" AppendDataBoundItems="True" runat="server"
DataTextField="Description" DataValueField="CommonCodeId" TabIndex="4"
CssClass="drop_red_style1" AutoPostBack="True" CausesValidation="True"
OnSelectedIndexChanged="DropDownList_SelectedIndexChanged">
</asp:DropDownList>

<asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server" ControlToValidate="DropDownList"
Display="Dynamic" InitialValue="0" SetFocusOnError="true" ValidationGroup="Registration">Required</asp:RequiredFieldValidator>
Please guide me how to keep the required fie

Completely disabling viewstate

  

Hi,
I am busy trying to build a mobile web site with ASP.NET and for it to 100% comply with XHTML Mobile 1.2, I need to completely disable viewstate.
At the moment I just have a very simple web site with one master.page and one content page (default.aspx). For both the master.page and default.aspx pages I have put 

Hi,

I am busy trying to build a mobile web site with ASP.NET and for it to 100% comply with XHTML Mobile 1.2, I need to completely disable viewstate.

At the moment I just have a very simple web site with one master.page and one content page (default.aspx). For both the master.page and default.aspx pages I have put (inside page_load):


Pag

DropDownList SelectedIndexChanged event not fired when programatically setting SelectedValue

  

In our asp.net web application we load the dropdown list boxes in the page load.  We than set the SelectedValue of each dropdown list box to an object from session.  We have event handlers for many of the SelectedIndexChanged events of the drop down lists boxes, but these do not get executed when we set the selected value programmatically.

 

Someone else mentioned this is by design, and only when a user manually changes the drop down list selected index, will the event get raised.

 

I would think this is a common scenario of wanting the selectedindexchanged event handled when setting the selectedvalue/selectedindex/listitem's selected property, of a DropDownList.  What is the suggested way to handle this?  Is there a significant drawback of creating a custom control inherited from DropDownList that has the functionality of raising this event when changing the SelectedIndex or SelectedValue?

 

 


DropDownList.SelectedIndexChanged not working

  

Hi,

I have the following in a web user control:

 

asp:DropDownList ID="ddlPrescriptionCodeGroup" runat="server" AppendDataBoundItems="True" AutoPostBack="True" DataSourceID

Update databse with DropDownList in GridView, SelectedIndexChanged

  

I am new to asp.net (I may use some incorrect termology while I explain my issue...) and need some help with DropDownList in Gridview.  Currently I have a GridView set up with three Columns bound to a database: Column1 - some kinda of index, Column2 - string, Column3 - DropDownList(called Active).  So far when I build the page, all the columns show up and the DropDownList appears and the values are bound correctly.  I want to change a value in the DropDownList and automatically update that value in my database. 


I have set AutoPostBack = true and I made a DataObject (called UpdateActive) to update the database (it takes 2 inputs, the Column1 index and Column3 DropDownList value).  However, I don't know how to find the row that I am changing, is there a way to figure out what row it is (like finding the Column 1 index?).  Also, I don't want to have to click a button to update the data.

                        <asp:GridView ID="gvWorkflowStepOrder" runat="server" AllowPaging="True" AllowSorting="true"
CssClass="tableBorderLight"
AutoGenerateColumns="False" DataKeyNames="WorkflowStepOrderID" PageSize="50"

Confirm DropDownList SelectedIndexChanged

  

Hello!

I want to check something with the users before they change the selectedvalue of a dropdownlist (DDL).

I use codebehind:

protected void ddlZavarovatelj_PreRender(object sender, EventArgs e)
        {
            DropDownList ddl = (DropDownList)detailsview1.FindControl("ddlZavarovatelj");
            ddl.Attributes.Add("onchange", "return window.confirm('Are you sure?');");
        }


Why if the user clicks "No" the selectedvalue still get's changed? Also why if the user clicks "Yes" the code from DDL's OnSelectedIndexChanged is not fired??

Thx,

M


Dropdownlist AutoPostBack="true" NOT Firing in IPhone

  

Hi everyone,

This is really weird...I have a ASP.NET page for mobile view.

On that page I have this part:

<td><asp:DropDownList ID="DropDownLocation" runat="server" AutoPostBack="true" OnSelectedIndexChanged="test" 
                            appenddatabounditems="True" style=" font-size:large; vertical-align:middle;" Width="170px">
                    <asp:ListItem value="Houston">Houston</asp:ListItem>
                    <asp:ListItem value="El Paso">El Paso</asp:ListItem>
                    <asp:ListItem value="Austin">Austin</asp:ListItem>
                    <asp:ListItem value="Boise">Boise</asp:ListItem>
                    <asp:ListItem value="Washington">Washington</asp:ListItem>
            </asp:DropDownList>

While testing this on normal computer using IE7 IE8 it fires the AutoPostBack Control.

BUT TESTING IN IPHONE THIS DOES NOT FIRES....

ALSO THE DISPLAY IS WIERD BECAUSE A SEPARATE BOX APPEARS AT THE BOTTOM TO SELECT THE LIST.

What am I doing wrong?

Thank you in advance!

 

 


Categories: 
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