[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

DropDownList selectedindex = -1 after postback

Posted on 2008-06-19
3
Medium Priority
?
3,907 Views
Last Modified: 2010-04-21
Hi Experts,

The dropdownlist (DDL1) on my aspx page gets populated on page load just fine. On page load I set the selectedindex to 1.

I have Autopostback set to false on the dropdownlist.

When I click on a button, and go to the function behind that button click Updatebtn_Click(), I want to retrieve the selected item in DDL1. However, at this point I get an object reference error and DDL1.selectedindex = -1.

Could you tell me what's going on and how I can get the selected value without a flash on the page?

Here's the aspx:
Dropdownlist:
<asp:DropDownList AutoPostBack="false" ID="DDL1" runat="server" Font-Size="X-Small" width="120"></asp:DropDownList>

Button:
<asp:Button ID="Updatebtn" runat="server" Text="Update" Font-Size="1.0em" OnClick="Updatebtn_Click" />

The page has enableviewstate set to false.


Here's the code behind:

protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack && !Page.IsCallback)
        {

            InitAlertsPanel();

            DataTable dt = (DataTable)Session["dataTable"];
            grid1.DataSource = dt;
            grid1.KeyFieldName = "RowNumber";
            grid1.DataBind();


            // Register trigger for update panel
            ScriptManager1.RegisterAsyncPostBackControl(Button1);
            AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
            trigger.EventName = "Click";

            if (Button1.UniqueID.EndsWith(trigger.ControlID))
            {
                trigger.ControlID = Button1.UniqueID.ToString();
            }

        }
        else
        {
            //Bind the grid on every request
            BuildGrid1();


        }

        if (!IsPostBack){
            GetUPendingStatus(); // This populates DDL1

        }

0
Comment
Question by:rss2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Expert Comment

by:burakiewicz
ID: 21823659
to get it form the codebehind you need it to postback, if you can use ajax then you could put the ddl in an update panel, and you wont see the screen flash
0
 
LVL 37

Accepted Solution

by:
samtran0331 earned 2000 total points
ID: 21824233
>>The page has enableviewstate set to false.

ViewState is what holds the values of controls.
Try either enabling viewstate on the entire page or just on the dropdownlist.
0
 

Author Closing Comment

by:rss2
ID: 31468860
Thank you SO MUCH!!! :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question