文本框的值没有得到清除文本框

2023-09-10 20:06:02 作者:画一方禁地囚我于无期°

在低于code文本框的值不获取点击按钮后清除。

In the below code TextBox value is not getting cleared after clicking on Button.

Default.aspx的

Default.aspx

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <br />
    <asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="20">
    </asp:Timer>
    <br />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <Triggers>
                <asp:AsyncPostBackTrigger controlid="Timer1" eventname="Tick" />
            </Triggers>
        <ContentTemplate>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <asp:Repeater ID="Shout_Box" runat="server">
            <ItemTemplate>
               <%# DataBinder.Eval(Container.DataItem, "Message") %>
            </ItemTemplate>
        </asp:Repeater>

        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:TextBox ID="TextBox1" runat="server">
        </asp:TextBox>
    </form>
</body>
</html>

C#$ C $下按钮的点击。

C# code for button click.

protected void Button1_Click(object sender, EventArgs e)
{
    string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=repeater;" + "UID=root;" + "PASSWORD=********;" + "OPTION=3";
    OdbcConnection MyConnection = new OdbcConnection(MyConString);
    OdbcCommand cmd = new OdbcCommand("INSERT INTO table1(message)VALUES(?)", MyConnection);
    cmd.Parameters.Add("@email", OdbcType.VarChar, 255).Value = TextBox1.Text;
    MyConnection.Open();
    cmd.ExecuteNonQuery();
    MyConnection.Close();
    TextBox1.Text = "";
}

我尝试添加一行如上 TextBox1.Text =; 来清除文本,但没有用。 请不要问我保持按钮UpdatePanel的标签之外。我需要的事件,而不回发的页面做的事情。

I tried adding a line as above TextBox1.Text = ""; to clear text but no use. Please do not ask me to keep Button outside the updatepanel tag. I need the event to be done without posting back the page.

如果文本框里面由于定时器触发永远20 fsecs文本框太闪烁,不允许修改。说来简单文本框是令人耳目一新,而不是让文字甚至一位来补充。

If TextBox is inside Due to timer trigger for ever 20 fsecs the textbox is too blinking and not allowing to edit. To say simply TextBox is refreshing and not allowing even a single bit of text to add.

我不希望这种扩展到Java脚本等,以清除文本框的值。谁能告诉我如何使用C#来清除文本框的值。

I don't want to extend this to JavaScripts and other to clear a value in textbox. Can anybody tell me how to clear the textbox value using C#.

推荐答案

使用另一个更新面板和的Page_Load 函数添加 UpdatePanedid.Update() ;。希望这可以帮助你。

Use another update panel and in Page_Load function add UpdatePanedid.Update(); Hope this helps you.

 
精彩推荐
图片推荐