按钮上的UpdatePanel中的PostBack单击

时间:2014-02-17 09:23:48

标签: asp.net updatepanel

我在我的网站上添加了一个ScriptManager和一个UpdatePanel。运行隔离的代码将起作用。但是在我的页面中运行代码总是让Page跳转到Scrollposition 1(我认为它是一个完整的回发)。

隔离了代码snipplet,它在一个独立的页面中工作,如下所示:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
         <asp:UpdatePanel ChildrenAsTriggers="false" UpdateMode="Conditional" ID="UpdatePanel1" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" />
            </Triggers>
             <ContentTemplate>
                <asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label><br />
                <asp:Button ID="Button2" runat="server" OnClick="Button1_Click" Text="Button" />
             </ContentTemplate>
         </asp:UpdatePanel> 

请你帮我说出我做错了什么?以下是整个页面内容:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" %>

<script runat="server">

    public Dictionary<string, string> properties;
    public JiraServices.PropertyService propertyService;

    public void getAllDropdownLabels()
    {
        txtDebug.Text = "";
        string allTextBoxValues = "init... ";
        foreach (Control c in Page.Controls)
        {

            foreach (Control childc in c.Controls)
            {
                foreach (Control childchildc in childc.Controls)
                {
                    foreach (Control childchildchildc in childchildc.Controls)
                    {
                        if (childchildchildc is DropDownList)
                        {
                            string ausgewaehlterWert = (((DropDownList)childchildchildc).SelectedItem!=null) ? ((DropDownList)childchildchildc).SelectedItem.ToString() : "leer!";

                            if (properties.ContainsKey(childchildchildc.ID.ToString()))
                            {
                                // auswählen
                                int selIndex = ((DropDownList)childchildchildc).Items.IndexOf(((ListItem)((DropDownList)childchildchildc).Items.FindByText(properties[childchildchildc.ID.ToString()])));
                                ((DropDownList)childchildchildc).SelectedIndex = selIndex;
                            }
                            else
                            {
                                // einfügen
                                propertyService.createProperty(childchildchildc.ID.ToString(), ausgewaehlterWert);
                                properties = propertyService.getAllProperties();
                            }

                        }
                    }
                }
            }
        }

        txtDebug.Text = allTextBoxValues;        
    }

    protected void Page_Load(object sender, EventArgs e)
    {
       propertyService = new JiraServices.PropertyService();
       properties = propertyService.getAllProperties();
    }

    protected void Page_LoadComplete(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "Hallo!";
    }


    protected void Page_PreRenderComplete(object sender, EventArgs e)
    {
        getAllDropdownLabels();
    }

    protected void Page_Init(object sender, EventArgs e)
    {

    }

    protected void ddlResearchPlanning_SelectedIndexChanged(object sender, EventArgs e)
    {
        string dropDownListId = ((DropDownList)sender).ID.ToString();
        string dropDownListValue = ((DropDownList)sender).SelectedItem.Text;

        txtDebug.Text += dropDownListId + ";" + dropDownListValue + "\n";

        propertyService.setProperty(dropDownListId, dropDownListValue);
    }

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style1
        {
            text-align: left;
            vertical-align: top;
        }
        .style2
        {
            text-align: left;
            vertical-align: top;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
         <asp:UpdatePanel ChildrenAsTriggers="false" UpdateMode="Conditional" ID="UpdatePanel1" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" />
            </Triggers>
             <ContentTemplate>
                <asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label><br />
                <asp:Button ID="Button2" runat="server" OnClick="Button1_Click" Text="Button" />
             </ContentTemplate>
         </asp:UpdatePanel>        
         <br />
        <h2>Responsibilities</h2>
         <br />
        This is the administration area to set up the responsibilities for each workflow step.<br />
        <h3>Research</h3>
        <table>
            <tr>
                <td class="style1">Research Planning</td><td>
                <asp:DropDownList ID="ddlResearchPlanning" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID" AutoPostBack="true" 
                    onselectedindexchanged="ddlResearchPlanning_SelectedIndexChanged">
                </asp:DropDownList>
                <asp:SqlDataSource ID="dsUsers" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:DP_JIRAConnectionString %>" 
                    SelectCommand="SELECT DISTINCT u.ID, u.display_name, u.user_name, u.email_address FROM cwd_user AS u INNER JOIN cwd_membership AS m ON u.ID = m.child_id ORDER BY 3" >
                </asp:SqlDataSource>
                </td>
             </tr>
            <tr>
                <td class="style1">Concept</td>
                <td>
                <asp:DropDownList ID="ddlConcept" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>               
                </td>
             </tr>
            <tr>
                <td class="style1">Patent</td><td>
                <asp:DropDownList ID="ddlPatent" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
                </td>
             </tr>
            <tr>
                <td class="style1">RA / RM, TUV</td><td>
                <asp:DropDownList ID="ddlRARMTUV" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
                </td>
             </tr>
            <tr>
                <td class="style1">Implementation</td><td> 
                <asp:DropDownList ID="ddlImplementation" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
                </td>
             </tr>
            <tr>
                <td class="style1">Test</td><td>
                <asp:DropDownList ID="ddlTest" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
                </td>
             </tr>
            <tr>
                <td class="style1">Design Review Research</td><td>
                <asp:DropDownList ID="ddlDesignReviewResearch" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>

                </td>
             </tr>
        </table>
        <h3>&nbsp;</h3>
         <h3>Design Control</h3>
        <table>
            <tr>
               <td class="style2">Design Planning</td><td>
                <asp:DropDownList ID="ddlDesignPlanning" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">Product Requirements</td><td>
                <asp:DropDownList ID="ddlProductRequirements" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">Sytem Requirements</td><td>
                <asp:DropDownList ID="ddlSystemRequirements" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">System UI</td><td>
                <asp:DropDownList ID="ddlSystemUI" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">System Functional RA / RM</td><td>
                <asp:DropDownList ID="ddlSystemFunctionalRaRM" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">System Design Review</td><td>
                <asp:DropDownList ID="ddlSystemDesignReview" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">Component Requirements</td><td>
                <asp:DropDownList ID="ddlComponentRequirements" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">Mechanics</td><td>
                <asp:DropDownList ID="ddlMechanics" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">Cabling</td><td>
                <asp:DropDownList ID="ddlCabling" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">Electronic Hardware</td><td>
                <asp:DropDownList ID="ddlElectronicHardware" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">Software</td><td>
                <asp:DropDownList ID="ddlSoftware" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList></td>
            </tr>
            <tr>
               <td class="style2">SW Language English update</td><td>
                <asp:DropDownList ID="ddlSWLanguageEnglishUpdate" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">Filters</td><td>
                <asp:DropDownList ID="ddlFilters" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">Disposables</td><td>
                <asp:DropDownList ID="ddlDisposables" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">Others</td><td>
                <asp:DropDownList ID="ddlOthers" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">Labeling - IFU, SM, etc</td><td>
                <asp:DropDownList ID="ddlLabeling" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">Integration Test</td><td>
                <asp:DropDownList ID="ddlIntegrationTest" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">System V&V</td><td>
                <asp:DropDownList ID="ddlSystemVnV" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>
            <tr>
               <td class="style2">ChC documentation</td><td>
                <asp:DropDownList ID="ddlChCDocumentation" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>                              
            <tr>
               <td class="style2">Design Review</td><td>
                <asp:DropDownList ID="ddlDesignReview" runat="server" DataSourceID="dsUsers" 
                    DataTextField="user_name" DataValueField="ID">
                </asp:DropDownList>
</td>
            </tr>                                                                      
        </table>
         <asp:TextBox ID="txtDebug" runat="server" Height="136px" TextMode="MultiLine" Width="512px"></asp:TextBox>
         <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</asp:Content>

1 个答案:

答案 0 :(得分:1)

您好我发现这是主页中MOO工具的错误:

    <script type="text/javascript" src="assets/mootools-1.js"></script>
    <script type="text/javascript" src="assets/mootools-1_002.js"></script>
    <script type="text/javascript" src="assets/mootools-tabswapper-clientcide-trunk-656.js"></script>
    <script type="text/javascript" src="assets/mootools-slimbox-clientcide-trunk-661.js"></script>
    <script type="text/javascript" src="assets/mootools-autocompleter.js"></script>
    <script type="text/javascript" src="assets/swfobject.js"></script>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src="assets/98.htm"></script>