Solved

How to determine which function was triggered

Posted on 2008-10-03
2
386 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

829 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