Solved

How to determine which function was triggered

Posted on 2008-10-03
2
402 Views
Last Modified: 2012-08-13
Hi Experts,
I have a web site I've developed using Ajax CascadingDropDowns.  I have an issue.  I have a button to update a database with information from the drop downs.  The problem is that whenever I click the button, the page does the "Page_Load" event, the "DropDownList_SelectedIndexChanged" event and THEN the Button_Click event!

I bypass the Page_Load event using the if (!IsPostBack), but I cannot do that for the DropDownList4_SelectedIndexChanged, because it IS a postback (auto post back).  How do I bypass the DropDownList4_SelectedIndexChanged (and DropDownList5) event without breaking the autopostback?

in the code behind:
    protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
    {
        ShowImageMaps();
    }
 
    protected void DropDownList5_SelectedIndexChanged(object sender, EventArgs e)
    {
        SelectMotors(false);
    }
 
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (GetDataForSave())
        {
            Response.Redirect("main.aspx");
        }
    }
 
In the aspx page:
<%@ Page Language="C#" AutoEventWireup="true" EnableSessionState="true" EnableEventValidation="false"  CodeFile="eIQ.aspx.cs" Inherits="eIQ"%>
 
<!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">
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <title>Quote Part 1</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div style="margin-left:10px; margin-top:10px;">
    <h4>Project Name:<asp:Label ID="lblProjectName" runat="server" Text="Project Name Goes Here"></asp:Label></h4>
    <h4>Project Owner:<asp:Label ID="lblProjectOwner" runat="server" Text="Project Owner"></asp:Label></h4>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <asp:Table ID="Table1" runat="server">
            <asp:TableRow runat="server">
             <asp:TableCell runat="server" HorizontalAlign="Center" Width="35%" Wrap="False">
                <table border="1" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>Series</td>
                        <td><asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
                        <ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1" Category="systypes"  PromptText="Please select a series"  LoadingText="[Loading series...]" ServicePath="TypeService.asmx" ServiceMethod="GetSystems" Enabled="True" />
                        </td>
                    </tr>
                    <tr>
                        <td>Enclosure</td>
                        <td><asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>
                        <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="DropDownList2" Category="enclosure" PromptText="Please select an enclosure" LoadingText="[Loading enclosures...]" ServicePath="TypeService.asmx" ServiceMethod="GetEnclosureForSystem" ParentControlID="DropDownList1" Enabled="True" />
                        </td>
                    </tr>
                    <tr>
                        <td>Speed</td>
                        <td><asp:DropDownList ID="DropDownList3" runat="server"></asp:DropDownList>
                        <ajaxToolkit:CascadingDropDown ID="CascadingDropDown3" runat="server" TargetControlID="DropDownList3" Category="speed" PromptText="Please select a Speed" LoadingText="[Loading speeds...]" ServicePath="TypeService.asmx" ServiceMethod="GetSpeedForEnclosures" ParentControlID="DropDownList2" Enabled="True" />
                        </td>
                    </tr>
                    <tr>
                        <td>Manufacturer</td>
                        <td><asp:DropDownList ID="DropDownList4" runat="server" OnSelectedIndexChanged="DropDownList4_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
                        <ajaxToolkit:CascadingDropDown ID="CascadingDropDown4" runat="server" TargetControlID="DropDownList4" Category="manufacturer"  PromptText="Please select a manufacturer"  LoadingText="[Loading manufacturers...]" ServicePath="TypeService.asmx" ServiceMethod="GetManufacturers" ParentControlID="DropDownList3" Enabled="True" />
                        </td>
                    </tr>
                    <tr>
                        <td>Model</td>
                        <td><asp:DropDownList ID="DropDownList5" runat="server" OnSelectedIndexChanged="DropDownList5_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
                        <ajaxToolkit:CascadingDropDown ID="CascadingDropDown5" runat="server" TargetControlID="DropDownList5" Category="equip"  PromptText="Please select a model"  LoadingText="[Loading models...]" ServicePath="TypeService.asmx" ServiceMethod="GetModels" ParentControlID="DropDownList4" Enabled="True" />
                        </td>
                    </tr>
                </table>
             </asp:TableCell>
             <asp:TableCell runat="server" HorizontalAlign="Center" Width="25%" Wrap="False">
            </asp:TableCell>
            <asp:TableCell runat="server" HorizontalAlign="Center" Width="35%" Wrap="False">
                <asp:Table ID="tblHP" runat="server" BorderColor="Black" BorderStyle="solid" BorderWidth="2" Visible="false">
                <asp:TableRow ID="tpHeader" runat="server" BorderWidth="2" BorderStyle="Solid" Font-Size="large">
                    <asp:TableHeaderCell ID="thhLine" runat="server" Text="" BorderWidth="2" BorderStyle="Solid"></asp:TableHeaderCell>
                    <asp:TableHeaderCell ID="thhPump" runat="server" Text="Select Pump" HorizontalAlign="Left" BorderWidth="2" BorderStyle="Solid"></asp:TableHeaderCell>
                    <asp:TableHeaderCell ID="thhHP" runat="server" Text="Motor HP" BorderWidth="2" BorderStyle="Solid"></asp:TableHeaderCell>
                </asp:TableRow>
                <asp:TableRow ID="trPump1" runat="server">
                    <asp:TableCell ID="tcLine1" runat="server" Text="" AssociatedHeaderCellID="thhLine"></asp:TableCell>
                    <asp:TableCell ID="tcPump1" runat="server" Text="" AssociatedHeaderCellID="thhPump"><asp:DropDownList ID="ddlPump1" runat="server" DataValueField="ID"></asp:DropDownList></asp:TableCell>
                    <asp:TableCell ID="tcHP1" runat="server" Text="" AssociatedHeaderCellID="thhHP"><asp:DropDownList ID="ddlHP1" runat="server" DataTextField="HORSEPOWER" DataValueField="ID"></asp:DropDownList></asp:TableCell>
                </asp:TableRow>
                </asp:Table>
             </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow ID="TableRow1" runat="server">
                <asp:TableCell ID="TableCell1" runat="server" ColumnSpan="2" HorizontalAlign="right">
                    <asp:Label ID="lblUpdated" runat="server" Text="" Visible="false"></asp:Label>
                    <asp:Button ID="Button1" runat="server" Text="Update" OnClick="Button1_Click" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow runat="server">
                <asp:TableCell runat="server" ColumnSpan="3" HorizontalAlign="Center">
                    <asp:Image ID="imgPumpCurve" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
    </ContentTemplate>
    </asp:UpdatePanel>
    </div>
    </form>
    <a href="main.aspx">Return to Main Page</a>
</body>
</html>

Open in new window

0
Comment
Question by:ericlockshine
[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
2 Comments
 
LVL 7

Expert Comment

by:ajolly
ID: 22641661
I am a bit confused.
If DropDownList4_SelectedIndexChanged is fired due to autopostback that means as soon as you change the index, it will be executed, you will have no time to click the button.

and when the button is clicked, only the button's click event will be fired.
0
 

Accepted Solution

by:
ericlockshine earned 0 total points
ID: 22641725
ajolly, when the index is changed in the drop down li fires the event, no problem there, that is what I want it to do.  It basically changes a picture on the screen.  The page remains.  The problem was that the button would fire in this order:  Page_Load, DropDownList4_SelectedIndexChanged, DropDownList5_SelectedIndexChanged and then Button1_Click.

To fix it, I moved the button and image OUTSIDE the update panel into its own update panel, and set the UpdateMode to conditional and ChildrenAsTriggers to true inside the original panel.  This allows me to keep the same layout, let the picture change dynamically.  But thanks for your question.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 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