如何在回发时清除文本框 [英] How to clear textbox on postback

查看:85
本文介绍了如何在回发时清除文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在按钮点击事件中重置所有文本框。但是当我刷新页面时,控制值仍保留在它们之间。



我尝试过EnableViewState = False选项但不能正常工作。



我看到这篇文章并且声明



ViewState和Postback [ ^ ]



一个有趣的行为是,如果我们创建一个实现IPostBackEventHandler接口禁用的控件,那么ASP.NET将不会处理回发期间的控件。所以在上面的示例中,如果我们禁用Textbox(一个EnableViewState = false),那么它将不会保留更改的值并且表现得像标签控件。



现在,谁能告诉我如何使用这个界面



谢谢,

Bh @gyesh

解决方案

参考这个



clear-textbox- post-postback [ ^ ]



如何在回发后清除文本框值 [ ^ ]



希望它会有所帮助..


< blockquote>在页面加载事件中尝试这个..



 如果( IsPostBack)
{
TextBoxControl.Text = String .Empty;
}


  void  CleareAllcontrolsRecursive(控件容器) )
{
foreach var control in container.Controls)
{
if (control TextBox)
{
((TextBox)control).Text = string .Empty;
}

}
}







在按钮点击事件中调用CleareAllcontrolsRecursive(panelcontrol)方法..

并且所有控件都应该在Panel标签中...


Hi,

I am reset all textboxes on button click event. but when I refresh page the control values are remain with them.

I have tried EnableViewState=False option but not working.

I saw this article and it is stated that

ViewState and Postback[^]

"An interesting behavior is if we make a control which implements IPostBackEventHandler interface disabled then the ASP.NET will not process the control during postback. So in the above sample, if we make the Textbox (one with EnableViewState = false) disabled then it will not retain the changed value and behave like a label control."

Now, can anyone tell me how can I work with this interface

Thanks,
Bh@gyesh

解决方案

Refer this

clear-textbox-after-postback[^]

How to clear text box values after postback[^]

Hope it will help..


On page load event try this..

if(IsPostBack)
{
TextBoxControl.Text = String.Empty;
}


void CleareAllcontrolsRecursive(Control container)
   {
       foreach (var control in container.Controls)
       {
           if (control is TextBox)
           {
               ((TextBox)control).Text = string.Empty;
           }        
        
       }
   }




call CleareAllcontrolsRecursive(panelcontrol) method in button click event..
and all controls should be in Panel tag...


这篇关于如何在回发时清除文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆