Problems with asp.net ajax and drop down lists

Last post 05-05-2009 9:53 PM by haydenm315. 15 replies.

Sort Posts:

  • Problems with asp.net ajax and drop down lists

    04-30-2009, 10:31 PM
    • Member
      1 point Member
    • haydenm315
    • Member since 04-30-2009, 10:01 PM
    • Posts 7

    First of all I'm using the latest visual studio 2008 with asp.net ajax 3.5 or whatever. I am having issues where my ajax post backs are taking forever when I add a dropdownlist. At least I think that's what is happening. Soon as I bind the drop down list my page starts bogging the browser when I click on the prev/next record button.  I'm new to this and becoming more and more frustrated with asp.net :(   I figured I could broaden my horizons and do this project with somehting other than java, but this is driving me nuts! 

     Here is some code from my page.  A little background.  I'm trying to populate a drop downlist full of company names, along with a proposal database record.  The proposal record has a company name which I'd like to select in the dropdown.  I have a number of updatepanels on the page which hold information about the proposal record. I have navigation buttons at the bottom for going through the proposal record.

    I've been able to page through the records fine and with decent speed UNTIL I started messing with a dropdown list.  The page initially loads fine, but when I click on a previous/next button it takes a very long time to update.  There is a night and day difference if I don't databind the billing company name dropdownlist.  If someone could explain why adding this dropdownlist is killing my performance I'd be very grateful.

    Initially I had the dropdown list in the update panel.  It was super slow doing page updates.  There are maybe a couple hundred company names.  I'm only pulling 1 proposal record back at a time on each click of the prev/next button.  I read some on the net and removed the dropdownlist from the updatepanel which didn't help. I had the dropdownlist in the update panel because I thought it make things easy updating the selected value based on the proposal record's company id.

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //initialize table adapters for proposal and proposal details
                ProposalsDSTableAdapters.tblProposalsTableAdapter proposalsAdapter =
                    new ProposalsDSTableAdapters.tblProposalsTableAdapter();
                ProposalsDS.tblProposalsDataTable proposals =
                    new ProposalsDS.tblProposalsDataTable();
                proposals = proposalsAdapter.GetData();
                int lastProposalID = (int)proposalsAdapter.LastProposalID();
    
                ProposalsDS.tblProposalsRow proposalRow = 
                    proposalsAdapter.GetDataByProposalID(lastProposalID)[0];
    
                //populate the company names dropdown
                populateCompanyNames();
    
                refreshProposal(proposalRow);
                refreshProposalDetails(proposalRow);
    
                txtRecordNum.Text = proposalsAdapter.GetNumberOfRows().ToString();
            }
        }
    
        protected void populateCompanyNames()
        {
            RolodexTableAdapters.tblAddressesTableAdapter rolodexAdapter =
               new RolodexTableAdapters.tblAddressesTableAdapter();
            Rolodex.tblAddressesDataTable companyNames = new Rolodex.tblAddressesDataTable();
            companyNames = rolodexAdapter.GetCompanyNames();
    
            DropDownListBillingCompanyName.DataSource = companyNames;
            DropDownListBillingCompanyName.DataValueField =
                companyNames.CompanyIDColumn.ColumnName.ToString();
            DropDownListBillingCompanyName.DataTextField =
                companyNames.CompanyNameColumn.ColumnName.ToString();
            DropDownListBillingCompanyName.DataBind();
        }
      
        protected void refreshProposal(ProposalsDS.tblProposalsRow row)
        {
            //update the dropdownlist with the current proposals 
            //company id.
            DropDownListBillingCompanyName.SelectedValue = row.CompanyID.ToString();
            
            txtProposalNum.Text = row.ProposalID.ToString();
            txtDate.Text = row.Proposaldate.ToShortDateString();
    
            lblBillingStreet.Text = row.CompStreetaddress;
            LblContactFax.Text = row.Contactfax;
    
            lblContactPhone.Text = row.Contactph;
            lblBillingCountry.Text = row.CompCountry;
            LblBillingEmail.Text = row.Contactemail;
            LblContactFax.Text = row.Contactfax;
        } 
    
       protected void refreshProposalDetails(ProposalsDS.tblProposalsRow row)
        {
            ProposalsDSTableAdapters.tblProposaldetailsTableAdapter
                proposalDetailsAdapter = new ProposalsDSTableAdapters.
                    tblProposaldetailsTableAdapter();
            ProposalsDS.tblProposaldetailsDataTable proposalDetails =
                new ProposalsDS.tblProposaldetailsDataTable();
            GridViewProposalDetails.DataSource =
                proposalDetailsAdapter.GetDataByProposalID(row.ProposalID);
            GridViewProposalDetails.DataBind();
        }
    
        protected void btnNext_Click(object sender, EventArgs e)
        { 
            //initialize table adapters for proposal and proposal details
            ProposalsDSTableAdapters.tblProposalsTableAdapter proposalsAdapter =
                new ProposalsDSTableAdapters.tblProposalsTableAdapter();
            ProposalsDS.tblProposalsDataTable proposal =
                new ProposalsDS.tblProposalsDataTable();
    
            int proposalID = int.Parse(txtProposalNum.Text.Trim());
            
            proposal = proposalsAdapter.GetNextProposalByID(proposalID);
            ProposalsDS.tblProposalsRow proposalRow = proposal[0];
    
            refreshProposal(proposalRow);
            refreshProposalDetails(proposalRow);
            //populate the navigation fields
            int recordNum = int.Parse(txtRecordNum.Text);
            recordNum++;
            txtRecordNum.Text = recordNum.ToString();
        }
    
        protected void btnPrevRecord_Click(object sender, EventArgs e)
        {
            //initialize table adapters for proposal and proposal details
            ProposalsDSTableAdapters.tblProposalsTableAdapter proposalsAdapter =
                new ProposalsDSTableAdapters.tblProposalsTableAdapter();
            ProposalsDS.tblProposalsDataTable proposal =
                new ProposalsDS.tblProposalsDataTable();
            
            int proposalNum = int.Parse(txtProposalNum.Text);
            proposal = proposalsAdapter.GetPrevProposalByID(proposalNum);
            
            ProposalsDS.tblProposalsRow proposalRow = proposal[0];
    
            refreshProposal(proposalRow);
            refreshProposalDetails(proposalRow);
            
            //populate the navigation fields
            int recordNum = int.Parse(txtRecordNum.Text);
            recordNum--;
            txtRecordNum.Text = recordNum.ToString();        
       }
     
     
  • Re: Problems with asp.net ajax and drop down lists

    05-01-2009, 8:06 AM
    • Contributor
      2,288 point Contributor
    • anup_daware
    • Member since 02-23-2006, 12:37 PM
    • India, Pune
    • Posts 417

    I will try to solve your issue and hope you start respecting asp.net a little more after that :)

    First thing to check is, what exactly eating up your processing time: Lets try out following:

    1. Do not populate the dropdown, instead use hardcoded values and test the page

    This will help us to determine if the data access layer that is fetching data the dropdown is slow.

    2. If performance is still not good use the existing logic of populating the dropworn on a fresh page

    If this is found slow, we can say that the business logic somewhere is not efficient

    3.  If issue is not solved, try setting update mode of update panel conditional

    As you said, you are having number of update panels on your page, this can also trun in to a potential problem. Many update panels on page can kill the application. By default the update mode of update panels is 'always' change it to conditional and call update() where ever is necessary  only.

    Read following: 

    http://forums.asp.net/t/1296488.aspx

     

    We can look in further in this issue if nothing mentioned above helps.

     -- Anup Daware

    --Go for it now. The future is promised to no one.--
  • Re: Problems with asp.net ajax and drop down lists

    05-01-2009, 10:12 AM
    • Member
      1 point Member
    • haydenm315
    • Member since 04-30-2009, 10:01 PM
    • Posts 7
    Thanks for the response.  I get the drop down list populated on the page load fast so I think that's ok.  It's when I do a partial page update with ajax is the issue.  I made all of my updatePanels conditional with no effect.  It doesn't seem to matter if the dropdown is in an updatepanel or not, though I've read having a dropdown with thousands of options in an updatepanel is bad news.  Using firefox with firebug, I was able to get more of an idea what's happening.   I don't understand it, but I have more clues.  If I databind the dropdown box, I get a bad AJAX post response about validation.  Without firebug installed, the response would seemingly hang the browser.  Without the databind call on the dropdownlist I get no such validation error returned from the ajax post.  Below is the AJAX response error.
    505|error|500|Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation
    ="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes
    , this feature verifies that arguments to postback or callback events originate from the server control
     that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation
     method in order to register the postback or callback data for validation.

    If I don't bind DropDownListBilling, it's not in the post and I dont' get the error.  I dont' understand why it's even in the post since it's outside an update panel. 

    If I add EnableEventValidation="false" to the top of the page I don't get the error in firefox, but my IE still hangs... maybe since it's old ie 6.  I'm interesting in understanding

    why this databind causes validation problems in the event. Below is the Post which gives me that error.

     DropDownListBillingCompanyName 2217
    S1
    ScriptManager1 UpdatePanel3|btnPrevRecord
    __ASYNCPOST true
    __EVENTARGUMENT
    __EVENTTARGET
    __EVENTVALIDATION /wEWDALjtbrgBQLR3v1hAoXnv9MCAsSEqIMOAu+ymIwNAvzy8KMMAoOQiL4EAoGx7IIJAo2R+JIOAuC5/8wMAvmGnOwPApvRtIcEfSGzvVF3Jk2U5VmL9OjYmyJbIZw
    =
    __LASTFOCUS
    __VIEWSTATE /wEPDwULLTEwNTY0ODM4MDRkGAEFF0dyaWRWaWV3UHJvcG9zYWxEZXRhaWxzDzwrAAoBCAIBZPPeKhiGrKIT8VPffxbdPFzQyuvM
    btnPrevRecord Prev
    txtDate 3/9/2009
    txtProposalNum 21596
    txtPurchaseOrder
    txtRecordNum 296
     

    it takes me 2 clicks on the prev record button to get the error.  Strangely enough it will go to the first previous record.  There is something interesting in the first post request that isn’t in the second.

    __EVENTVALIDATION (Very Large Data)

     

  • Re: Problems with asp.net ajax and drop down lists

    05-01-2009, 11:06 AM
    • Contributor
      2,288 point Contributor
    • anup_daware
    • Member since 02-23-2006, 12:37 PM
    • India, Pune
    • Posts 417

    You are having too many problems in one page. but looks like your viewstate is overloaded!

    May be if page itself is very heavy with lots of functionality I suggest you to reorganize the pages and put some functionality in different page.

    But before that:

    Just do one quick check, disable the viewstate for entire page and check the performance. I know you may need the viewsatate but I am asking you to do this just to reach the correct issue.

    Also, please report the  the size of __VIEWSTATE parameter

     

    Thanks,

    Anup Daware

     

    --Go for it now. The future is promised to no one.--
  • Re: Problems with asp.net ajax and drop down lists

    05-01-2009, 12:08 PM
    • Member
      1 point Member
    • haydenm315
    • Member since 04-30-2009, 10:01 PM
    • Posts 7

    I turned viewstate off at the top of the page. Nothing has changed. I installed a plugin for firefox that says ViewState is .07kb

    In the post it looks pretty small as well. I'm assuming the below is the ViewState? __VIEWSTATE /wEPDwULLTEwNTY0ODM4MDRkGAEFF0dyaWRWaWV3UHJvcG9zYWxEZXRhaWxzDzwrAAoBCAIBZA==
  • Re: Problems with asp.net ajax and drop down lists

    05-01-2009, 12:15 PM
    • Member
      299 point Member
    • soharadesign
    • Member since 04-29-2009, 8:46 AM
    • Hemel Hempstead, UK
    • Posts 69

    It wont be viewstate - it will be your data layer. Whats happening is that your dropdown is refreshing the data on every action. You need to figure out a way to only update this if/when it changes. An ajax panel that has its update mode to conditional isn't a bad first step.

     

    Ultimately, if your data is fairly static, I would recommend loading the whole list into the cache and querying it from there. You should notice a significant improvement this way.

    Steve O'Hara

    Sohara Design
  • Re: Problems with asp.net ajax and drop down lists

    05-01-2009, 12:18 PM
    • Contributor
      2,288 point Contributor
    • anup_daware
    • Member since 02-23-2006, 12:37 PM
    • India, Pune
    • Posts 417

    Do you want to say that all the problems that were existing before disabling viewstate still persists and there is no improvement in performance?

    Also, comment out all update panels on the page and test again.

    Could you post your entire aspx page and aspx.cs page here?

    I will try and go through it whenever I get some time. 

     

    Thanks,

    Anup Daware

    --Go for it now. The future is promised to no one.--
  • Re: Problems with asp.net ajax and drop down lists

    05-01-2009, 12:59 PM
    • Member
      1 point Member
    • haydenm315
    • Member since 04-30-2009, 10:01 PM
    • Posts 7

    Yes, I am saying nothing changed when I disabled viewstate. I commented out all the update panels and all is good except no more ajax. I've posted the page below. If you could teach me what I'm doing wrong with the ajax that woudl be great.

    function pageLoad() { } #TextArea1 { margin-left: 0px; z-index: 1; left: 11px; top: 39px; position: absolute; height: 56px; width: 375px; } #TextArea { width: 459px; text-align: left; height: 85px; z-index: 1; left: 9px; top: 4px; position: absolute; }
       







  • Re: Problems with asp.net ajax and drop down lists

    05-01-2009, 1:31 PM
    • Star
      8,753 point Star
    • Pawan_Mishra
    • Member since 03-13-2008, 11:37 AM
    • Bangalore
    • Posts 1,279

    Hi 

    I guess the problem lies with the number of records which are getting binded with dropdown list control . I have seen atleast 5-10 queries on the same issue wherein page hangs during asynchronous postback . 

    Following is one comment which I found in some blog on the same issue ( UpdatePanel + DropDownList) :-

    "The only response I can give is that the UpdatePanel is having to use XmlHttp
    to marshal a large amount of "string-ified" data over the wire and reassemble
    it in the callback to fit your control's needs. There are some situations
    where AJAX just doesn't "fit" and this is probably one of them. Either that,
    or don't bring back so much data at one time." Click here

    If I would have been in your situation then I wouldnt have used the dropdownlist control . Rather I would have gone for something called as "AutoComplete" feature .  Wherein I will fetch data only if a user looks for it . You can also call it as delayed loading ( kind of delayed loading ).

     

    Regards
    Pawan Mishra

    Moving from Asp.Net to WPF and SilverLight .....

    .Net 360°
  • Re: Problems with asp.net ajax and drop down lists

    05-01-2009, 1:32 PM
    • Contributor
      2,288 point Contributor
    • anup_daware
    • Member since 02-23-2006, 12:37 PM
    • India, Pune
    • Posts 417

     Ok this is good, so now we know that the issue is with Ajax :)

    I didnt get your code right, please post it again.

    --Go for it now. The future is promised to no one.--
  • Re: Problems with asp.net ajax and drop down lists

    05-01-2009, 1:36 PM
    • Contributor
      2,288 point Contributor
    • anup_daware
    • Member since 02-23-2006, 12:37 PM
    • India, Pune
    • Posts 417

     can you just try putting update panel again and disabling viewstate of dropdown control and ckeck again, i know I have made you test the page with viewstate disabled for page level but still.

     

    Also, bring back your update panels one by one and see which one exactly is the culprit.

     

    Hope something comes out of this,

    Anup Daware

    --Go for it now. The future is promised to no one.--
  • Re: Problems with asp.net ajax and drop down lists

    05-01-2009, 3:42 PM
    • Member
      1 point Member
    • haydenm315
    • Member since 04-30-2009, 10:01 PM
    • Posts 7

    another shot at the code.

    1    <%@ Page Language="C#" DEBUG="true" EnableViewState="false" AutoEventWireup="true" CodeFile="Proposals.aspx.cs" Inherits="Proposals" EnableEventValidation="true" EnableViewStateMac="False" ViewStateEncryptionMode="Never" %>
    2    
    3    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    4    
    5    <html xmlns="http://www.w3.org/1999/xhtml">
    6    <head runat="server">
    7        <title></title>
    8        <script type="text/javascript">
    9    
    10           function pageLoad() 
    11               {
    12         }
    13       
    14       </script>
    15       <style type="text/css">
    16           #TextArea1
    17           {
    18               margin-left: 0px;
    19               z-index: 1;
    20               left: 11px;
    21               top: 39px;
    22               position: absolute;
    23               height: 56px;
    24               width: 375px;
    25           }
    26           #TextArea
    27           {
    28               width: 459px;
    29               text-align: left;
    30               height: 85px;
    31               z-index: 1;
    32               left: 9px;
    33               top: 4px;
    34               position: absolute;
    35           }
    36       </style>
    37   </head>
    38   <body>
    39       <form id="form1" runat="server" enableviewstate="False">
    40       <asp:ScriptManager ID="ScriptManager1" runat="server">
    41       </asp:ScriptManager>
    42       <div style="position: relative; top: 0px; left: 0px;">
    43           <%--asp:UpdatePanel ID="UpdatePanelHeader" runat="server" RenderMode="Inline">
    44               <ContentTemplate--%>        
    45                   <nobr>
    46                       <asp:Label ID="Label1" runat="server" Text="Proposal #: "></asp:Label>
    47                       <asp:TextBox ID="txtProposalNum" runat="server" Width="127px" 
    48                       AutoPostBack="True"></asp:TextBox>
    49                       <asp:Label ID="Label2" runat="server" Text="PO#: " style="position: relative"></asp:Label>
    50                       <asp:TextBox ID="txtPurchaseOrder" runat="server" 
    51                       style="position: relative" EnableViewState="False"></asp:TextBox>
    52                          
    53                       <asp:Label ID="Label3" runat="server" Text="Date:"></asp:Label>
    54                       <asp:TextBox ID="txtDate" runat="server" 
    55                       ontextchanged="txtDate_TextChanged"></asp:TextBox>
    56               <%--/ContentTemplate>
    57           </asp:UpdatePanel--%>        
    58           <asp:Label ID="Label4" runat="server" Text="ES: "></asp:Label>
    59           <asp:DropDownList ID="DropDownListES" runat="server" Width="170px" 
    60               EnableViewState="False">
    61           </asp:DropDownList>
    62       </div>
    63       <div style="height: 104px; width: 323px; z-index: 1; left: 12px; top: 54px; position: absolute">
    64           <asp:Button ID="btnSearchBilling" runat="server" 
    65               style="z-index: 1; left: 8px; top: 26px; position: absolute" Text="Find" 
    66               EnableViewState="False" />
    67           <asp:Label ID="Label5" runat="server" 
    68                style="z-index: 1; left: 57px; top: 1px; position: absolute" 
    69               Text="Bill To:"></asp:Label>
    70           <div style="z-index: 2; left: 59px; top: 18px; position: absolute; height: 84px; width: 264px">
    71                 <asp:DropDownList ID="DropDownListBillingCompanyName" runat="server" Height="23px" 
    72                 Width="260px" EnableTheming="False" EnableViewState="False">
    73               </asp:DropDownList><br />
    74               <%--asp:UpdatePanel ID="BillingCompany" runat="server">
    75                   <ContentTemplate--%>
    76                       <asp:Label ID="lblBillingStreet" runat="server" Text="Billing Street"></asp:Label><br />
    77                       <asp:Label ID="lblBillingCityStateZip" runat="server" 
    78                           Text="City, State, Zipcode"></asp:Label><br />
    79                       <asp:Label ID="lblBillingCountry" runat="server" Text="Billing Country"></asp:Label>                
    80                   <%--/ContentTemplate>
    81               </asp:UpdatePanel--%>
    82            </div>   
    83       </div>
    84        <div style="height: 103px; width: 234px; z-index: 1; left: 341px; top: 56px; position: absolute">
    85            <div style="height: 80px; z-index: 1; left: 38px; top: 19px; position: absolute; width: 197px;">
    86               <asp:DropDownList ID="DropDownListContactName" runat="server" Height="22px" Width="175px" 
    87                    EnableViewState="False">
    88                  </asp:DropDownList>
    89               <%--asp:UpdatePanel ID="UpdatePanel1" runat="server"
    90                    EnableViewState="False" UpdateMode="Conditional">
    91                   <ContentTemplate--%>
    92                       <asp:Label ID="lblContactPhone" runat="server" Text="(410) 888-3422 ext 255"></asp:Label>
    93                       <br />
    94                       <asp:Label ID="LblContactFax" runat="server" Text="(410) 888-333-3422"></asp:Label>
    95                       <br />
    96                       <asp:Label ID="LblBillingEmail" runat="server" Text="test@somebody.com"></asp:Label>
    97                   <%--/ContentTemplate>
    98                </asp:UpdatePanel--%>
    99            </div>
    100           <asp:Label ID="Label6" runat="server" 
    101               style="z-index: 1; left: 36px; top: -1px; position: absolute" Text="Contact:"></asp:Label>
    102           <asp:Label ID="Label7" runat="server" 
    103               style="z-index: 1; left: 14px; top: 42px; position: absolute" Text="ph:" 
    104               EnableViewState="False"></asp:Label>
    105           <asp:Label ID="Label8" runat="server" 
    106               style="z-index: 1; left: 11px; top: 62px; position: absolute" Text="fax:"></asp:Label>
    107           <asp:Label ID="Label9" runat="server" 
    108               style="z-index: 1; left: -2px; top: 79px; position: absolute" 
    109               Text="email:" EnableViewState="False"></asp:Label>
    110      </div>
    111      <div style="z-index:1; left: 580px; top: 54px; position: absolute; height: 101px; width: 198px;">
    112          <asp:Label ID="Label10" runat="server" 
    113              style="z-index: 1; left: 0px; top: -1px; position: absolute" 
    114              Text="Ship To:" EnableViewState="False"></asp:Label>
    115          <asp:Button ID="ButtonClear" runat="server" 
    116              style="z-index: 1; left: 131px; top: 4px; position: absolute; height: 20px; width: 42px; font-size: x-small" 
    117              Text="Clear" />
    118          <asp:Button ID="ButtonPickup" runat="server" 
    119              style="z-index: 1; left: 83px; top: 4px; position: absolute; height: 20px; width: 42px; font-size: x-small" 
    120              Text="Pickup" EnableViewState="False" />
    121          <div style="height: 76px; position: absolute; top: 20px; left: 0px; z-index: 1; width: 198px;">
    122              <asp:DropDownList ID="DropDownListJobName" runat="server"                 
    123                  style="z-index: 1; left: 0px; top: 0px; position: absolute; height: 20px; width: 189px" 
    124                  EnableViewState="False">
    125              </asp:DropDownList>
    126              <asp:Label ID="LabelShipToName" runat="server" Text="Ship to name"></asp:Label><br />
    127              <asp:Label ID="LbllShipToStreet" runat="server" Text="Ship to street"></asp:Label><br />
    128              <asp:Label ID="LbllShipToCityStateZip" runat="server" 
    129                  Text="City, State, Zipcode"></asp:Label>     
    130          </div>
    131      </div>
    132      <div style="z-index:1; left: 14px; top: 173px; position: absolute; height: 158px; width: 767px; overflow-y: scroll;">
    133          <%--asp:UpdatePanel ID="UpdatePanel2" runat="server" RenderMode="Inline">
    134              <ContentTemplate--%>
    135                  <asp:GridView ID="GridViewProposalDetails" runat="server" 
    136                      style="font-size: small; margin-top: 0px;" Height="12px" Width="764px" BackColor="White" 
    137                      BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
    138                      GridLines="Vertical">
    139                      <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
    140                      <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
    141                      <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    142                      <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
    143                      <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
    144                      <AlternatingRowStyle BackColor="#DCDCDC" />
    145                  </asp:GridView>
    146              <%--/ContentTemplate>
    147          </asp:UpdatePanel--%>
    148      </div>
    149      <div style="z-index:1; left: 14px; top: 356px; position: absolute; height: 102px; width: 767px; text-align: center;">
    150          <textarea id="TextArea" name="S1"></textarea></div>
    151      <div style="z-index:1; left: 12px; top: 470px; position: absolute; height: 33px; width: 752px; text-align: center;">    
    152          <%--asp:UpdatePanel ID="UpdatePanel3" runat="server">
    153              <ContentTemplate--%>
    154                  <asp:Button ID="btnFirstRecord" runat="server" Text="First" 
    155                      onclick="btnFirstRecord_Click" />
    156                  <asp:Button ID="btnPrevRecord" runat="server" Text="Prev" 
    157                      onclick="btnPrevRecord_Click" />                
    158                  <asp:TextBox ID="txtRecordNum" runat="server" AutoPostBack="True"></asp:TextBox>
    159                  <asp:Button ID="btnNextRecord" runat="server" Text="Next" 
    160                      onclick="btnNext_Click" />
    161                  <asp:Button ID="btnLastRecord" runat="server" Text="Last" 
    162                      onclick="btnLastRecord_Click" />
    163                  <asp:Label ID="lblTest" runat="server" Text="Label"></asp:Label>
    164              <%--/ContentTemplate>
    165          </asp:UpdatePanel--%>
    166      </div>
    167    </form>    
    168  </body>
    169  </html>
    170  
    
     
      function pageLoad() { }  
    1    
    2    using System;
    3    using System.Collections.Generic;
    4    using System.Linq;
    5    using System.Web;
    6    using System.Web.UI;
    7    using System.Web.UI.WebControls;
    8    
    9    public partial class Proposals : System.Web.UI.Page
    10   {
    11       protected void Page_Load(object sender, EventArgs e)
    12       {
    13           if (!IsPostBack)
    14           {
    15               //initialize table adapters for proposal and proposal details
    16               ProposalsDSTableAdapters.tblProposalsTableAdapter proposalsAdapter =
    17                   new ProposalsDSTableAdapters.tblProposalsTableAdapter();
    18               ProposalsDS.tblProposalsDataTable proposals =
    19                   new ProposalsDS.tblProposalsDataTable();
    20               proposals = proposalsAdapter.GetData();
    21               
    22               int lastProposalID = (int)proposalsAdapter.LastProposalID();
    23   
    24               ProposalsDS.tblProposalsRow proposalRow =
    25                   proposalsAdapter.GetDataByProposalID(lastProposalID)[0];
    26   
    27               //populate the company names dropdown
    28               populateCompanyNames();
    29               //populate the jobsite name field
    30               populateJobSite();
    31               //populate the contact names dropdown
    32               populateContactNameDropDown();
    33               refreshProposal(proposalRow);
    34               refreshProposalDetails(proposalRow);
    35               txtRecordNum.Text = proposalsAdapter.GetNumberOfRows().ToString();            
    36           }
    37       }
    38   
    39       protected void populateCompanyNames()
    40       {
    41           RolodexTableAdapters.tblAddressesTableAdapter rolodexAdapter =
    42              new RolodexTableAdapters.tblAddressesTableAdapter();
    43           Rolodex.tblAddressesDataTable companyNames = new Rolodex.tblAddressesDataTable();
    44           companyNames = rolodexAdapter.GetCompanyNames();
    45   
    46           DropDownListBillingCompanyName.DataSource = companyNames;
    47           DropDownListBillingCompanyName.DataValueField =
    48               companyNames.CompanyIDColumn.ColumnName;
    49           DropDownListBillingCompanyName.DataTextField =
    50               companyNames.CompanyNameColumn.ColumnName;
    51           DropDownListBillingCompanyName.DataBind();        
    52       }
    53   
    54       protected void populateContactNameDropDown()
    55       {
    56           RolodexTableAdapters.tblNamesTableAdapter rolodexAdapter =
    57              new RolodexTableAdapters.tblNamesTableAdapter();
    58           Rolodex.tblNamesDataTable contactNames =
    59               new Rolodex.tblNamesDataTable();
    60           /*
    61               contactNames = rolodexAdapter.GetContactNames();
    62          
    63           DropDownListContactName.DataSource = contactNames;
    64   
    65           DropDownListContactName.DataValueField =
    66               contactNames.NameIDColumn.ColumnName;
    67   
    68           DropDownListJobName.DataTextField =
    69               contactNames.LastNameColumn.ColumnName;
    70           */
    71           // DropDownListJobName.DataBind();
    72   
    73       }
    74   
    75       protected void populateJobSite()
    76       {/*
    77           RolodexTableAdapters.tblJobsitesTableAdapter jobSitesAdapter =
    78              new RolodexTableAdapters.tblJobsitesTableAdapter();
    79           Rolodex.tblJobsitesDataTable jobNames = new Rolodex.tblJobsitesDataTable();
    80           
    81           jobNames = jobSitesAdapter.GetJobNames();
    82   
    83           DropDownListJobName.DataSource = jobNames;
    84   
    85           DropDownListJobName.DataValueField =
    86               jobNames.CompanyIDColumn.ColumnName;
    87   
    88           DropDownListJobName.DataTextField =
    89               jobNames.JobnameColumn.ColumnName;
    90           
    91          // DropDownListJobName.DataBind();
    92         */
    93       }
    94   
    95       //This refreshes the proposal form fields
    96       protected void refreshProposal(ProposalsDS.tblProposalsRow row)
    97       {
    98           DropDownListBillingCompanyName.SelectedValue = row.CompanyID.ToString();
    99   
    100          txtProposalNum.Text = row.ProposalID.ToString();
    101          txtDate.Text = row.Proposaldate.ToShortDateString();
    102  
    103          lblBillingStreet.Text = row.CompStreetaddress;
    104          LblContactFax.Text = row.Contactfax;
    105  
    106          lblContactPhone.Text = row.Contactph;
    107          lblBillingCountry.Text = row.CompCountry;
    108          LblBillingEmail.Text = row.Contactemail;
    109          LblContactFax.Text = row.Contactfax;
    110  
    111          //LbllShipToCityStateZip.Text = row.ShiptoCity + " ," +
    112          //  row.ShiptoState + ". " + row.ShiptoZip;
    113          //LbllShipToStreet.Text = row.ShiptoStreetNo + " " +
    114          //  row.ShiptoStreetName;
    115          // LblShip
    116      }
    117  
    118      //This refreshes the proposal details table
    119      protected void refreshProposalDetails(ProposalsDS.tblProposalsRow row)
    120      {
    121          ProposalsDSTableAdapters.tblProposaldetailsTableAdapter
    122              proposalDetailsAdapter = new ProposalsDSTableAdapters.
    123                  tblProposaldetailsTableAdapter();
    124          ProposalsDS.tblProposaldetailsDataTable proposalDetails =
    125              new ProposalsDS.tblProposaldetailsDataTable();
    126          GridViewProposalDetails.DataSource =
    127              proposalDetailsAdapter.GetDataByProposalID(row.ProposalID);
    128          GridViewProposalDetails.DataBind();
    129      }
    130  
    131      protected void btnNext_Click(object sender, EventArgs e)
    132      {
    133          //initialize table adapters for proposal and proposal details
    134          ProposalsDSTableAdapters.tblProposalsTableAdapter proposalsAdapter =
    135              new ProposalsDSTableAdapters.tblProposalsTableAdapter();
    136          ProposalsDS.tblProposalsDataTable proposal =
    137              new ProposalsDS.tblProposalsDataTable();
    138  
    139          int proposalID = int.Parse(txtProposalNum.Text.Trim());
    140  
    141          proposal = proposalsAdapter.GetNextProposalByID(proposalID);
    142          ProposalsDS.tblProposalsRow proposalRow = proposal[0];
    143          populateCompanyNames();
    144          refreshProposal(proposalRow);
    145          refreshProposalDetails(proposalRow);
    146          //populate the navigation fields
    147          int recordNum = int.Parse(txtRecordNum.Text);
    148          recordNum++;
    149          txtRecordNum.Text = recordNum.ToString();
    150      }
    151  
    152      protected void btnPrevRecord_Click(object sender, EventArgs e)
    153      {
    154          //initialize table adapters for proposal and proposal details
    155          ProposalsDSTableAdapters.tblProposalsTableAdapter proposalsAdapter =
    156              new ProposalsDSTableAdapters.tblProposalsTableAdapter();
    157          ProposalsDS.tblProposalsDataTable proposal =
    158              new ProposalsDS.tblProposalsDataTable();
    159  
    160          int proposalNum = int.Parse(txtProposalNum.Text);
    161          proposal = proposalsAdapter.GetPrevProposalByID(proposalNum);
    162  
    163          ProposalsDS.tblProposalsRow proposalRow = proposal[0];
    164          populateCompanyNames();
    165          refreshProposal(proposalRow);
    166          refreshProposalDetails(proposalRow);
    167          
    168  
    169          //populate the navigation fields
    170          int recordNum = int.Parse(txtRecordNum.Text);
    171          recordNum--;
    172          txtRecordNum.Text = recordNum.ToString();
    173      }
    174      protected void btnLastRecord_Click(object sender, EventArgs e)
    175      {
    176          //get last proposal
    177          //int lastProposal = proposalsAdapter.LastProposalID().Value;
    178          //int firstProposal = proposalsAdapter.FirstProposalID().Value;
    179      }
    180      protected void btnFirstRecord_Click(object sender, EventArgs e)
    181      {
    182  
    183      }
    184      protected void txtDate_TextChanged(object sender, EventArgs e)
    185      {
    186  
    187      }
    188  }
    
      #TextArea1 { margin-left: 0px; z-index: 1; left: 11px; top: 39px; position: absolute; height: 56px; width: 375px; } #TextArea { width: 459px; text-align: left; height: 85px; z-index: 1; left: 9px; top: 4px; position: absolute; }
  • Re: Problems with asp.net ajax and drop down lists

    05-02-2009, 12:41 PM
    • Contributor
      2,288 point Contributor
    • anup_daware
    • Member since 02-23-2006, 12:37 PM
    • India, Pune
    • Posts 417

    Well, the code is still not complete.

    But, have you tried putting back update panels one by one and check the performance issue?

    Specially keep the updatepanel with dropworn commented and test if rest of the page is performing well.

    and if it is doing well there are couple of options for you, like auto complete exterder or page method to load the dropworn, that we can discuss later.

    I had also suggested you to test the page after disabling viewstate of problem dropdown only.

     

    Looking forward for your findings,

    Anup Daware

     

    -- Please mark posts 'Answered'  if they are helpful

    --Go for it now. The future is promised to no one.--
  • Re: Problems with asp.net ajax and drop down lists

    05-04-2009, 4:51 PM
    • Member
      1 point Member
    • haydenm315
    • Member since 04-30-2009, 10:01 PM
    • Posts 7

    I updated the code see above.  Sorry I fell off the internet, but I needed to replace my computer.   It was a PIII 733 and I ran out of patience.  Maybe that was part of the problem  The latest hand me down is much faster, but anyways back to the issue at hand.

     I've noticed the page updates smoothly in IE7.  I had IE6 on the previous machine.  Google chrome is extremely slow to update.  Firefox updates quickly now.  I'm not seeing the same behavior in the firebug output now.  I do see a massive string for event validation if I have that enabled.  That slows my ajax post backs down some.  I think the problems I've been seing are related to the event validation that comes back in the response.  It's gigantic. 

    There is a performance issue if the dropdown is inside the update panel, but not if it's outside.  I'm not sure what to make of this.  I will need to have a dropdown in the gridview control which I'm afraid is going to kill the page refreshes.  It would seem that ajax is not going to work for me here.  I'm kinda in a pickle because I'm trying to port an access application to asp.net.  I was hoping to make the asp.net forms similar to the access forms, using ajax to make it responsive, but maybe that's not an option since I'm already having issues paging through records.  I haven't even gotten to updating records. 

  • Re: Problems with asp.net ajax and drop down lists

    05-05-2009, 1:40 AM
    Answer
    • Star
      8,753 point Star
    • Pawan_Mishra
    • Member since 03-13-2008, 11:37 AM
    • Bangalore
    • Posts 1,279

    Hi

    I will advise you not to rely more on update panel for avoiding full page refresh . If you are really keen in avoiding postback then try to concentrate on asp.net ajax webservice consume very less bandwidth when compared with updatepanels .

    It will also be nice for you if you can understand how updatepanel works . In very simple words I can say that updatepanel simple replaces the contents which are contained inside it with fresh set of controls . Note : fresh set of controls ie the controls doesnt get updates but are actually replaced with new ones during async postback . Check out the following url for more on this :- http://forums.asp.net/t/1386696.aspx

    Regards
    Pawan Mishra

    Moving from Asp.Net to WPF and SilverLight .....

    .Net 360°
Page 1 of 2 (16 items) 1 2 Next >