Solved

How to determine which function was triggered

Posted on 2008-10-03
2
370 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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

13 Experts available now in Live!

Get 1:1 Help Now