First, I click btnClear button and system can clear the text of TBInput correctly after I select Yes in confirm window
then, I click Button1, and rewrite the text of TBInput
finish, I try to click  btnClear button again but confirm window don't display againHow can I do? Thanks! <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!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">
    <title></title>
    <script src="Js/jquery1.4.2.min.js" type="text/javascript"></script>
   
    <script type="text/javascript">
            $(document).ready(function () {
                $("#btnClear").click(function () {
                    if (confirm('Do you want to clear all expression in textbox?') == true) {
                        $("#TBInput").val("");
                    }
                })
            })    
    </script></head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:TextBox ID="TBInput" runat="server" ClientIDMode="Static">aa</asp:TextBox>
                <input id="btnClear" type="button" value="Clear" />
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>     protected void Button1_Click(object sender, EventArgs e)
    {
        TBInput.Text = "bb";
    }

解决方案 »

  1.   

    先等人把问题翻译成中文。跑起来看看页面源文件UpdatePanel1里的控件的id是不是还是TBInput,用这种<%=TBInput.ClientID%>
    $("#<%=TBInput.ClientID%>").val("");
      

  2.   

    UpdatePanel 有个这样的问题
    这样处理就OK
    但是AJAX效果就没了<asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:TextBox ID="TBInput" runat="server" ClientIDMode="Static">aa</asp:TextBox>
                    <input id="btnClear" type="button" value="Clear" />
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
                </ContentTemplate>
                <Triggers>
                    <asp:PostBackTrigger ControlID="Button1" />
                </Triggers>
            </asp:UpdatePanel>
      

  3.   

    这么简单的功能,直接用Jquery ajax,不用微软的这俩控件
      

  4.   

     赞成,如果是我,就用纯html脚本写了,不用服务器空间