?
Solved

How to determine which function was triggered

Posted on 2008-10-03
2
Medium Priority
?
407 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

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

752 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