母版页:按钮已更新,但仍然无效 [英] Master pages: button updated but remains inactive

查看:106
本文介绍了母版页:按钮已更新,但仍然无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,
我正在使用母版页来管理我的Web应用程序.当应用程序运行时,将出现的第一页是登录页,即我的母版页的子页.我在母版页上有一个按钮控件,应该在用户登录后启用,因此我将

Hi friends,
I am using master pages to manage my web application. When the application run the first page that will come is the login page which is child page of my master page. I have a button control on the master page which should be enabled after a user is logged in, so I put

Button1.Enabled = false;



在主页的Page_Load事件中.然后,将以下代码放入登录页面的提交"按钮中,以便启用button1(在母版页中)并将button1的标题更改为已登录"



in the Page_Load event of the master page. Then I put the following code in the submit button of the login page so that button1 (in the master page) will be enabled and the caption of the button1 will be changed to "Logged In"

Button bt;
myMasterpage  m = (myMasterpage)this.Master;
bt = m.FindControl("Button1") as Button;
bt.Enabled = true;
bt.Text = "Logged In";



结果:按钮的文本更改为已登录",但按钮仍处于非活动状态.你有什么建议?谢谢!

Getachew



Result: the text of the button is changed to "Logged In" but the button is still inactive. What do you suggest? Thanks!

Getachew

推荐答案

应该吗;

myMasterpage m = (myMasterpage)this.Master;

不;
MasterPage m = (MasterPage)this.Master;

我只是尝试了一下,如果您进行更改,它就可以满足您的要求.
但是,如果您再单击Button1,它将再次被禁用.

每次将页面重新加载/发布回服务器时,该按钮将再次被禁用,以防止在将其回发到母版页中的以下内容时加载
Should this;

myMasterpage m = (myMasterpage)this.Master;

not be;
MasterPage m = (MasterPage)this.Master;

I just tried it and it does what you want if you make the change.
However, if you then Click Button1, it becomes disabled again.

Everytime the page is reloaded/posted back to the server, the button will be disabled again, to prevent this on a postback to the following in the master page load
if (!this.IsPostBack)
{
    Button1.Enabled = false;
}



您还应该考虑做的是,将已登录状态存储在会话等中,并且仅根据此已登录状态有条件地设置按钮.



What you also should consider doing, is store the logged in state in the session etc. and also only conditionally set the button based on this logged in state.


这篇关于母版页:按钮已更新,但仍然无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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