Solved

How to determine which function was triggered

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net bundle 8 47
ASP.NET Web API or ASP.NET Core MVC? 3 53
Getting multiple values from a dataset ASP.NET(VB) 3 37
Host asp.net pages 5 26
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now