按钮禁用编码 [英] Button Disable Coding

查看:63
本文介绍了按钮禁用编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有两个ASP页面.
page1中有两个按钮(btn1btn2),在page2中也有两个按钮(insert update),如果我单击page1数据库中的btn1 数据显示在page2分配的文本框中,而我需要禁用page2中的insert按钮.
如果单击page1中的btn2,则在我需要禁用page2中的更新按钮时,TextBox将显示为空.
如何在不同的事件中禁用这两个按钮.

谢谢

Hi
I have two ASP pages.
In the page1 I have two buttons (btn1 and btn2), in page2 also I have two buttons (insert and update),If I click the btn1 in page1 database data are show in page2 assigned TextBox while I need to disable the insert button in page2.
If I click btn2 in page1, TextBox are shown in empty while I need to disable the update button in page2.
How can I disable these two buttons in different event.

Thanks

推荐答案

在您的第一页中,您可以将程序逻辑的结果存储到ViewState ...

In your first page you can store result of your program logic to ViewState...

protected void btn1_click(object sender, EventArgs e)
{
    this.ViewState["behavior"] = "update";
}

protected void btn1_click(object sender, EventArgs e)
{
    this.ViewState["behavior"] = "insert";
}


...然后您通过QueryString将结果作为参数发送给第二页.


...and later you send that result as parameter via QueryString to you second page.

if(ViewState["behavior"] != null)
{
    Response.Redirect("page2Url goes here?Behavior=" + ViewState["behavior"].ToString());
}
else
{
    //Business as usual
}



使用作为参数发送的信息,您可以在第二页的Load事件中轻松地在目标控件上设置所需的行为/属性值.



With information sent as parameter you can easily in Load event of second page set desired behavior/property values on targeted controls.

protected void Page2_Load(object sender, EventArgs e)
{
    if(!this.IsPostBack)
    {
        string arg = null;
        arg = Request.QueryString["behavior"];

        if(arg != null)
        {
            btnUpdate.Enabled = arg == "update";
            btnInsert.Enabled = arg == "insert";
            myTextBox.Text = btnInsert.Enabled ? "" : "bind some data on your own!";
        }
    }
}


在您的第一页中,单击按钮时您将重定向到另一页,因此,代替viewstate并检查文本框内容,将基于URL的值作为查询字符串传递给您可以在第二页中显示或隐藏按钮的值.
In your first page while clicking the buttons you are redirecting to another page so instead of viewstate and checking the text box content pass a value with url as query string based on the value you can show or hide buttons in second page.


您可以在page2的Page/Form加载事件上禁用

You can disable on Page/Form load event of page2

if(textbox.Text =="")
{
updbtn.ReadOnly=true;
insetbtn.ReadOnly=false;
}
else
{
pdbtn.ReadOnly=false;
insetbtn.ReadOnly=true;

}


这篇关于按钮禁用编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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