updateopatel中不会触发Autocompleteextender和按钮事件

时间:2012-10-28 19:31:18

标签: c# asp.net ajax updatepanel autocompleteextender

这里在我的代码中我创建了一个用户控件。将两个文本框与autocompleteextender放在一起并提交按钮。访问两个文本框后,提交按钮Click事件不会激活。代码有什么问题。请帮助我。当我把更新面板放在那之后它就无法正常工作了。我需要更新面板,因为两个文本框autopostback属性为true。

<asp:UpdatePanel runat="server" ID="UpQuote" UpdateMode="Always">
    <ContentTemplate>
        <div id="Quote">
            <table>
                <tr>
                    <td class="tbltdForQuote">
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label runat="server" ID="lblTitle" Text="Get an instant quote" CssClass="lblForQuote"
                            Font-Size="Large"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td class="tbltdForQuote">
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label runat="server" ID="lblTo" Text="Pick-up Location e.g. Heathrow" CssClass="lblForQuote"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:TextBox runat="server" ID="txtTo" AutoPostBack="true" autocomplete="off" CssClass="txtBoxForQuote" />
                        <ajaxToolkit:AutoCompleteExtender runat="server" BehaviorID="AutoCompleteEx1" ID="autoComplete1"
                            TargetControlID="txtTo" ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionList"
                            MinimumPrefixLength="1" CompletionInterval="1000" EnableCaching="true" CompletionSetCount="20"
                            CompletionListCssClass="autocomplete_completionListElement" CompletionListItemCssClass="autocomplete_listItem"
                            CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" DelimiterCharacters=";, :"
                            ShowOnlyCurrentWordInCompletionListItem="true">
                            <Animations>
                    <OnShow>
                        <Sequence>
                            <%-- Make the completion list transparent and then show it --%>
                            <OpacityAction Opacity="0" />
                            <HideAction Visible="true" />

                            <%--Cache the original size of the completion list the first time
                                the animation is played and then set it to zero --%>
                            <ScriptAction Script="
                                // Cache the size and setup the initial size
                                var behavior = $find('AutoCompleteEx1');
                                if (!behavior._height) {
                                    var target = behavior.get_completionList();
                                    behavior._height = target.offsetHeight - 2;
                                    target.style.height = '0px';
                                }" />

                            <%-- Expand from 0px to the appropriate size while fading in --%>
                            <Parallel Duration=".2">
                                <FadeIn />
                                <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx1')._height" />
                            </Parallel>
                        </Sequence>
                    </OnShow>
                    <OnHide>
                        <%-- Collapse down to 0px and fade out --%>
                        <Parallel Duration=".4">
                            <FadeOut />
                            <Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx1')._height" EndValue="0" />
                        </Parallel>
                    </OnHide>
                            </Animations>
                        </ajaxToolkit:AutoCompleteExtender>
                    </td>
                </tr>
                <tr>
                    <td class="tbltdForQuote">
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label runat="server" ID="lblFrom" Text="Drop-off Location e.g.E1 (Postcode)"
                            CssClass="lblForQuote"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:TextBox ID="txtFrom" AutoPostBack="true" runat="server" autocomplete="off" CssClass="txtBoxForQuote" />
                        <ajaxToolkit:AutoCompleteExtender runat="server" BehaviorID="AutoCompleteEx" ID="AutoCompletetxtFrom"
                            TargetControlID="txtFrom" ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionList"
                            MinimumPrefixLength="1" CompletionInterval="1000" EnableCaching="true" CompletionSetCount="20"
                            CompletionListCssClass="autocomplete_completionListElement" CompletionListItemCssClass="autocomplete_listItem"
                            CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" DelimiterCharacters=";, :"
                            ShowOnlyCurrentWordInCompletionListItem="true">
                            <Animations>
                    <OnShow>
                        <Sequence>
                            <%-- Make the completion list transparent and then show it --%>
                            <OpacityAction />
                            <HideAction Visible="true" />

                            <%--Cache the original size of the completion list the first time
                                the animation is played and then set it to zero --%>
                            <ScriptAction Script="
                                // Cache the size and setup the initial size
                                var behavior = $find('AutoCompleteEx');
                                if (!behavior._height) {
                                    var target = behavior.get_completionList();
                                    behavior._height = target.offsetHeight - 2;
                                    target.style.height = '0px';
                                }" />

                            <%-- Expand from 0px to the appropriate size while fading in --%>
                            <Parallel Duration=".2">
                                <FadeIn />
                                <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" />
                            </Parallel>
                        </Sequence>
                    </OnShow>
                    <OnHide>
                        <%-- Collapse down to 0px and fade out --%>
                        <Parallel Duration="1">
                            <FadeOut />
                            <Length PropertyKey="hight" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
                        </Parallel>
                    </OnHide>
                            </Animations>
                        </ajaxToolkit:AutoCompleteExtender>
                    </td>
                </tr>
                <tr>
                    <td class="tbltdForQuote">
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Button runat="server" ID="btnQuoteSubmit" Text="Get Quote >>" UseSubmitBehavior="false"
                            CssClass="QuoteButton" OnClick="btnQuoteSubmit_Click" CausesValidation="false" />
                    </td>
                </tr>
                <tr>
                    <td style="float: right">
                        <asp:HyperLink runat="server" ID="HyLogin" Text="Login to your account >>"></asp:HyperLink>
                    </td>
                </tr>
            </table>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

2 个答案:

答案 0 :(得分:0)

您可以尝试两件事。 1.在按钮声明中设置AutoPostBack="True"属性。或者,如果这不起作用,2。从更新面板中取出按钮。

答案 1 :(得分:0)

经过长时间的搜索,我找到了答案。基本上autocompleteextender不工作在用户控制。因为他们使用webmethod而且它只在网页上工作而不是用户控制