?
Solved

asp.net updatepanel causing unintended postbacks

Posted on 2013-11-21
6
Medium Priority
?
736 Views
Last Modified: 2014-06-13
I am working on a web page in asp.net (I am new to asp.net).  I have a script manager and two update panels (UpdatePanelCustomers and UpdatePanelItems) on my page, but I am experiencing a problem on post backs.  I have an image button (ibtnFilterCustomers) in the UpdatePanelCustomers panel, but when I click it, my UpdatePanelItems attempts to refresh and I get an exception (pasted below).  I cannot figure out how to resolve this.  I have set updatemode="conditional" for each panel, but that does not solve it.  However, if I move the button outside of the UpdatePanelCustomers and click it then UpdatePanelItems does not refresh (which is the intended action).  I would like to keep the button inside of the panel.  Please help me understand why this is happing and how to resolve it.    Maybe it would be best to handle all activity from the Click_Event and avoid the postback - but I don't know how to do that either.  Thanks in advance for your help.


Exception:
JavaScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Input string was not in a correct format.

Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="OrderEntry._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title> SBS Order Entry </title>
    
    <style type="text/css">
        .style1
        {
            width: 960px;
        }
        .style2
        {
            width: 144px;
            color: White;
            text-align: right;
            font-size: small;
        }
        .style3
        {
            color: #FFFFFF;
            font-size: smaller;
        }
        h1
        {
            font-family: Impact;
            font-size: xx-large;
            font-variant: small-caps;
            color: #FFFFFF;
        }
        h2
        {
            font-family: Impact;
            font-size: x-large;
            font-variant: small-caps;
            color: #FFFFFF;
        }
        #banner
        {
            height: 4
            0px;
            width: 960px;
            color: #FFFFFF;
            z-index: 1;
            left: 10px;
            top: 15px;
            position: absolute;
            background-color: #000000;
        }
       
        form
        {
            background-color: #000000;
            color: #FFFFFF;
            width: 958px;
            height: 1044px;
        }
       
        .style7
        {
            height: 25px;
        }
       
        .style8
        {
            width: 550px;
        }
        .style9
        {
        }
        .style10
        {
            width: 785px;
        }
       
        .style11
        {
        }
       
        .style12
        {
            width: 151px;
        }
       
        .style13
        {
            width: 150px;
        }
               
        .style15
        {
            font-family: Impact;
            font-size:xx-large;
            font-variant: small-caps;
            color: #FFFFFF;
            width: 250px;
        }
       
        .style16
        {
            font-family: "Accord SF";
            font-weight: bold;
        }
        .style17
        {
            width: 144px;
            color: White;
            text-align: right;
            font-size: small;
            height: 21px;
        }
        .style18
        {
            height: 21px;
        }
        .style19
        {
            color: #FFFFFF;
            font-size: smaller;
            width: 134px;
        }
        .style20
        {
            height: 25px;
            width: 134px;
        }
        .style21
        {
            color: #FFFFFF;
            font-size: smaller;
            width: 92px;
        }
        .style22
        {
            height: 25px;
            width: 92px;
        }
        .style23
        {
            color: #FFFFFF;
            font-size: smaller;
            width: 189px;
        }
        .style24
        {
            height: 25px;
            width: 189px;
        }
       
    </style>
</head>
<body bgcolor="#000000">
    <form id="form" runat="server" title="SBS Order Entry" >
      
    <div id="banner">
            <h1 style="width: 960px">
                <asp:Image ID="Image1" runat="server" 
                    ImageUrl="~/Images/Page_Header.png" Height="56px" Width="960px" /></h1>
        <h2 style="width: 960px"></h2>
    </div>
    
    <div id="main">
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
         <asp:ScriptManager ID="sm" runat="server" ScriptMode="Release" >
                        </asp:ScriptManager>
         
    <asp:UpdatePanel ID="UpdatePanelCustomers" runat="server" updatemode="conditional" > <%--AJAX Control that will allow partial postbacks (instead of full page post back) --%>
                <ContentTemplate> <%--Content Template for the Update Panel --%>               
         <asp:MultiView ID="mvCustomer" runat="server" ActiveViewIndex="0">
           
                       
        <asp:View ID="vSelectedCustomer" runat="server">
        <table class="style1">
        <tr>
            <td class="style2" valign="middle">
                Customer:</td>
            <td headers=" " class="style7">
                <asp:DropDownList ID="ddlCustomers" runat="server" AppendDataBoundItems="True" borderstyle="None" 
                    AutoPostBack="True" Height="17px" Width="250px" BackColor="Black" ForeColor="White" 
                    onselectedindexchanged="ddlCustomers_SelectedIndexChanged" 
                    CssClass="style3">
                    <asp:ListItem Value="" Text="Select a Customer..." />
                </asp:DropDownList>
               
                <asp:TextBox ID="txtCustomer" runat="server" BackColor="White" 
                    BorderStyle="None" ForeColor="Black"></asp:TextBox>
                <asp:ImageButton ID="ibtnFilterCustomers" runat="server" BorderStyle="None" 
                    ImageUrl="~/Images/BookOpen.gif" onclick="ibtnFilterCustomers_Click" 
                    Width="16px" />
            </td>
        </tr>
        <tr>
            <td class="style17">
                Address:</td>
            <td class="style18">
                <asp:Label ID="lblAddress" runat="server" CssClass="style3"></asp:Label>
            </td>
        </tr>
        <tr>
            <td class="style2">
                City, State Zip:</td>
            <td>
                <asp:Label ID="lblCity" runat="server" CssClass="style3"></asp:Label>
                <span class="style3">,
                </span>
                <asp:Label ID="lblState" runat="server" CssClass="style3"></asp:Label>
                &nbsp;<asp:Label ID="lblZip" runat="server" CssClass="style3"></asp:Label>
            </td>
        </tr>
        <tr style="height:10px" >
            <td class="style2">
                </td>
            <td>
            </td>
        </tr>
        </table>
       
        <table class="style1">
        <tr>
            <td class="style2">
                Contact:</td>
            <td class="style19">
                <asp:TextBox ID="txtContact" runat="server" BackColor="White" 
                    BorderStyle="None" ForeColor="Black"></asp:TextBox>
            </td>
            <td class="style21">
                &nbsp;</td>
            <td class="style23">
                &nbsp;</td>
            <td class="style3">
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style2">
                Phone:</td>
            <td class="style19">
                <asp:TextBox ID="txtPhone" runat="server" BackColor="White" BorderStyle="None" 
                    ForeColor="Black"></asp:TextBox>
            </td>
            <td class="style21">
                &nbsp;</td>
            <td class="style23">
                &nbsp;</td>
            <td class="style3">
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style2">
                &nbsp;</td>
            <td class="style20">
                &nbsp;</td>
            <td class="style22">
                &nbsp;</td>
            <td class="style24">
                &nbsp;</td>
            <td class="style7">
                &nbsp;</td>
        </tr>
    </table>
    
    </asp:View>
        
          
        <asp:View ID="vFilteredCustomers" runat="server">
            <asp:GridView ID="GridView1" runat="server">
            </asp:GridView>
        
        </asp:View>
    </asp:MultiView>
    </ContentTemplate>
            </asp:UpdatePanel>
    </div>
    
   
    <asp:UpdatePanel ID="UpdatePanelItems" runat="server" updatemode="Conditional"> <%--AJAX Control that will allow partial postbacks (instead of full page post back) --%>
                <ContentTemplate> <%--Content Template for the Update Panel --%>
    
    
    <asp:MultiView ID="mvConfigurations" runat="server" ActiveViewIndex="0">
           
                       
        <asp:View ID="vHardware" runat="server">
            
            <table class="style8">
                <tr>
                    <td class="style2">
                        Segment:</td>
                    <td class="style11" colspan="2">
                        <asp:DropDownList ID="ddlSegments" runat="server" AppendDataBoundItems="True" 
                            BackColor="Black" borderstyle="None" CssClass="style3" ForeColor="White" 
                            Height="21px" onselectedindexchanged="ddlSegments_SelectedIndexChanged" 
                            Width="431px" AutoPostBack="True">
                            <asp:ListItem Text="Choose a Segment..." Value="" />
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td class="style12">
                        <asp:RadioButtonList ID="rblItemManf" runat="server" CellSpacing="0" 
                            Font-Size="10pt" ForeColor="White" Height="47px" 
                            onselectedindexchanged="rblItemManf_SelectedIndexChanged" Width="160px" 
                            AutoPostBack="True">
                            <asp:ListItem>All Manufactures</asp:ListItem>
                            <asp:ListItem>XXXXX Only</asp:ListItem>
                            <asp:ListItem>Non-XXXXX Only</asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                    <td class="style11">
                        <asp:RadioButtonList ID="rblItemType" runat="server" CellSpacing="0" 
                            Font-Size="10pt" ForeColor="White" 
                            onselectedindexchanged="rblItemType_SelectedIndexChanged" Width="111px" 
                            AutoPostBack="True">
                            <asp:ListItem>All</asp:ListItem>
                            <asp:ListItem>B\W</asp:ListItem>
                            <asp:ListItem>Color</asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                    <td class="style10" valign="bottom">
                        <asp:Button ID="btnFetch" runat="server" BackColor="Black" BorderStyle="None" 
                            ForeColor="#0080FF" Height="21px" onclick="btnFetch_Click" 
                            Text="Fetch Items &gt;" Width="91px" />
                    </td>
                </tr>
                <tr>
                    <td class="style9" colspan="3">
                        
                    </td>
                </tr>
            </table>
            
            <asp:ObjectDataSource ID="odsHardwareItems" runat="server" 
                SelectMethod="GetFilteredHardwareList" TypeName="SBS_OrderEntry.DAL">
                <SelectParameters>
                    <asp:ControlParameter ControlID="ddlSegments" DefaultValue="null" Name="s" 
                        PropertyName="SelectedValue" Type="String" />
                    <asp:ControlParameter ControlID="rblItemManf" DefaultValue="null" Name="m" 
                        PropertyName="SelectedValue" Type="String" />
                    <asp:ControlParameter ControlID="rblItemType" DefaultValue="null" Name="t" 
                        PropertyName="SelectedValue" Type="String" />
                </SelectParameters>
            </asp:ObjectDataSource>
            <%--Since my button is outside of the UpdatePanel I need to set the Trigger on the Update Panel
            If the button was inside the update panel then there is no need to do a trigger because it is wrapped in the update panel
            If I did not set the trigger on the update panel with an AsyncPostBackTrigger (controlID = button, event = click) then the full page would post back (not using AJAX)
            
             --%>
            <asp:UpdateProgress ID="progress" runat="server" DisplayAfter="300" DynamicLayout="false" >
                <ProgressTemplate>
                   
                    <table class="style8">
                        <tr>
                            <td class="style13" align="right">
                            <img alt="Data Loading Please Wait..." src="Images/Progress_Clock_Red_Black.gif" />
                                &nbsp;</td>
                            <td class="style15" align="center" >
                                <span class="style16"><i>Loading... </i></span>&nbsp;</td>
                            <td class="style13" align="left">
                            <img alt="Data Loading Please Wait..." src="Images/Progress_Clock_Red_Black.gif" />
                                &nbsp;</td>
                        </tr>
                    </table>
                </ProgressTemplate>
            </asp:UpdateProgress>
                <asp:GridView ID="gvHardwareItems" runat="server" AllowPaging="True" 
                AllowSorting="True" AutoGenerateColumns="False" BackColor="#CCCCCC" 
                BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" 
                CellSpacing="2" DataSourceID="odsHardwareItems" ForeColor="Black" 
                onselectedindexchanged="gvHardwareItems_SelectedIndexChanged" 
                Width="550px">
                <RowStyle BackColor="White" />
                <Columns>
                    <asp:CommandField ButtonType="Image" SelectImageUrl="~/Images/Book.gif" 
                        SelectText="" ShowSelectButton="True" />
                    <asp:BoundField DataField="ItemID" HeaderText="ItemID" SortExpression="ItemID" 
                        Visible="False" />
                    <asp:BoundField DataField="Item" HeaderText="Item" SortExpression="Item" />
                    <asp:BoundField DataField="BW_Color" HeaderText="Type" 
                        SortExpression="BW_Color" />
                    <asp:BoundField DataField="Make" HeaderText="Make" SortExpression="Make" />
                    <asp:BoundField DataField="Segment" HeaderText="Segment" 
                        SortExpression="Segment" />
                    <asp:BoundField DataField="SegmentDescription" HeaderText="Segment Description" 
                        SortExpression="SegmentDescription" />
                </Columns>
                <FooterStyle BackColor="#CCCCCC" />
                <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" 
                        Font-Underline="False" />
            </asp:GridView>
                
            <%--<asp:GridView ID="gvHardwareItems" runat="server" 
                BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" 
                CellPadding="4" CellSpacing="2" ForeColor="Black" AllowPaging="True" 
                AllowSorting="True" AutoGenerateColumns="False" 
                >
                <RowStyle BackColor="White" />
                <FooterStyle BackColor="#CCCCCC" />
                <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                <Columns>
                            <asp:CommandField ShowSelectButton="True" 
                               SelectText="" SelectImageUrl ="~/Images/Book.gif" ButtonType="Image"></asp:CommandField>
                            <asp:BoundField HeaderText="ItemID" 
                               DataField="ItemID" 
                               SortExpression="ItemID"
                               Visible="False">
                            </asp:BoundField>
                            <asp:BoundField HeaderText="Item" 
                               DataField="Item" 
                               SortExpression="Item">
                            </asp:BoundField>
                            <asp:BoundField HeaderText="Type" 
                                DataField="BW_Color" 
                                SortExpression="BW_Color">
                            </asp:BoundField>
                            <asp:BoundField HeaderText="Make" 
                                DataField="Make" 
                                SortExpression="Make">
                            </asp:BoundField>
                            <asp:BoundField HeaderText="Segment" 
                                DataField="Segment" 
                                SortExpression="Segment">
                            </asp:BoundField>
                            <asp:BoundField HeaderText="SegmentDescription" 
                                DataField="SegmentDescription" 
                                SortExpression="SegmentDescription">
                            </asp:BoundField>                
                
               </Columns>

            </asp:GridView>--%>
            
        </asp:View>
        
          
        <asp:View ID="vAccessories" runat="server">
        </asp:View>
    </asp:MultiView>
          </ContentTemplate>
            </asp:UpdatePanel>
    </form>
</body>
</html>

Open in new window

0
Comment
Question by:toddpotter
  • 2
4 Comments
 
LVL 13

Expert Comment

by:Jitendra Patil
ID: 39668507
hi

try to add a trigger to the UpdatePanelCustomers panel as below

</ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="ibtnFilterCustomers" />
    </Triggers>
            </asp:UpdatePanel>

and also try with removing updatemode="conditional" from UpdatePanelCustomers.

hope this helps.
0
 

Author Comment

by:toddpotter
ID: 39668630
I tried as suggested, but the actions have not changed.  The UpdatePanelItems still posts back.
0
 
LVL 11

Accepted Solution

by:
Kelvin McDaniel earned 2000 total points
ID: 39687203
So... the first thing to understand is that ALL events on WebControls that are not fired off by an OnClientClick are full-on postbacks... they just don't seem to be because only the UpdatePanel(s) in question update on the client side. The server still does exactly the same amount of work, plus a little bit more because it has to figure out which parts to pass back and which ones to ignore.

I think this resource might explain what's going on with your page... "¿You [must] call the Update method of the UpdatePanel control explicitly [in your corresponding event codebehind method]."

Next, As patil786 said, make sure that you've got your Triggers defined correctly; the one that's "conditional" should be an asp:AsyncPostBackTrigger. Also, make sure that you read up on the stuff that's particular to the "Conditional" mode to ensure that you're not getting unintended behavior, both from those WebControls you intended to be conditional and the ones that you want to kick off normal postbacks.

So, going back and reading your post again, I realize that this is a two-part issue... the above addresses why the UpdatePanel isn't refreshing with the "Conditional" update.

The second part of this is that it seems like you're not posting the information that the server is expecting. You have to understand that while you're setting all this stuff up in the WebForm markup, at the end of the day it's emitting HTML and JavaScript. So... you're going to need a breakpoint at the beginning of your click handler event so you can TRY to see what's in the Request.Form collection. That may provide some clue as to what the server thinks is "missing" or "wrong".

IHTH!
0
 

Author Comment

by:toddpotter
ID: 39690967
Ok, so I added a button control next to the image button and when I click the button it processes fine with no error  - only the image button produces the error.  Now I need to figure out why!  For design purposes, I would really prefer to use the image button.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

621 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