从内容页面访问母版页控件 [英] Access Master Page control from the Content page
本文介绍了从内容页面访问母版页控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我有一个母版页,从中可以得出所有页面.在主页上,我有一个名为userLoginName的标签(默认情况下为空白.)
在登录页面上,在登录按钮的单击事件上,我有以下代码:
Hi
I have a master page from which i derive all the pages. On the master page i have a label called userLoginName (by default the text is blank.)
From the login page , on the click event of the login button i have this code:
Dim _logName = Trim(LoginName.Text)
Dim _pwd = Trim(Password.Text)
If Me.ValidateUser(_logName, _pwd) = True Then
'display users etails
Dim mpLabel As Label
mpLabel = CType(Master.FindControl("userLoginName "), Label)
'change the userLoginName text to: your login is successfull + user Name
mpLabel.Text = "your login is successfull" & _logName
'Redirect user to the appropriate page
If ViewState("_UserPrivilege") = "Administrator" Then
Response.Redirect("~/Adminstrator/index.aspx")
ElseIf ViewState("_UserPrivilege") = "Terminal User" Then
Response.Redirect("~/TerminalUsers/index.aspx")
End If
Else
StatusLabel.Text = "Please your login Name or Password is incorrect."
Exit Sub
End If
将页面重定向到适当的页面后,然后我看不到消息+用户登录名.
请帮助
After Redirecting the page to the appropriate page, then i dont see the message + user login name.
plz any help
推荐答案
此代码存在各种问题.但是,总的来说,我一直这样做的方法是为我所有的页面创建一个基础页面类.在该基类中,我公开了一个属性,该属性是页面的Master属性,转换为我正在使用的MasterPage类的类型.完成此操作后,我可以轻松地与内容页面中的母版页进行交互.但是,我永远不会直接公开文本框,而是公开一个属性来获取和设置其文本.
There''s all sorts of issues with this code. However, at the core, the way I always do this, is to create a base page class for all my pages. In that base class, I expose a property which is the Master property of the page, cast to the type of the MasterPage class I am using. Having done that, I can easily interact with my master page in my content pages. However, I would NEVER expose the textbox directly, I''d expose a property to get and set it''s text.
这篇关于从内容页面访问母版页控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文