Basically, I need to validate log-in on a child page which I've successfully done but now I'm required to edit a label on master page to show the Username of the user that successfully log in. This is basically a visual effect problem if you see it just like that but then I'm required to access the master page label from individual child page validate the username there with the table used for log-in and find out the permission status (admin or user), depending on the result activate or deactivate certain command buttons
My child log-in page is named :- Login.aspx
Master page :- Site.master
Master Label:- Label1
Codes I tried to use but they don't quite work
Master.FindControl("Label1").Visible=true;
Label lb=(Label)this.master.FindControl("Label1")
lb.visible=true
lb.text=UserName.text
Please help, I have been breaking my head for day to no avail got some good answers from here the past which I used hope to have the same luck
If you tell your master page to bind the label's value to HttpContext.User.Identity.Name, then you dont have to monkey around with anything in the child page.
In fact, I believe there's a built-in asp.net control for displaying the authentication status of a user.. though I could be wrong.
Related
There is a page Login.aspx having a Label control as "Lbl_LoginExpired".
There is also a MasterPage.
I want to change the text of "Lbl_LoginExpired" from within the Master Page.
How can i achieve this?
Note:
1) Login.aspx is NOT a Content page.
2) Label label1=new (Label)Login.FndControl("Lbl_LoginExpired")
is NOT working in MasterPage.
If there is no master page- content relationship between these 2 pages. I think your options are limited. Also i am assuming Lbl_LoginExpired is not a part of an user control that you can register in both pages. I would recommend using Session object to pass this information between these 2 pages.
Hence in your master page
Session["expiredtext"] = "Your login has been expired";
And in your login pag check this session value whether it is null or not and show the content of it.
Lbl_LoginExpired.Text=Session["expiredtext"]?.ToString();
Also do not forget to reset (or abonden session when user logs out)
I have a user control, say control 1, that looks for control2, which is placed on the root master page : Site.Master
And this is how I am getting Control2 from Control 1 now,
MasterPage showMaster = this.Page.Master.Master;
MasterPage siteMaster = showMaster.Master;
Control2= siteMaster.FindControl("Control2");
The above code works fine. But because our application uses nested master pages, I am running into a bit of situation here.
How do I find control 2 dynamically regardless of where I put Control1 in which template? Becasue right now, depends on where I put Control1, and how nested is that template in relation to the Site.Master, I have to change how far up in the chain I get Site.Master in the Control 1 code.
Any good ideas on how I can avoid doing that?
Please advise.
i found a work around with recursively loading the control
I have to fix one issue in our application that, If child window is opened and user clicks on Browser back button i need to redirect to page asking username and password.
we have 400 aspx pages so just i need to modify in master page. I have code like below
function initPage(){
checkback();
}
This function is written in external javascript file and used in Master Page.
checkback function contains code like below
if (document.forms[0].cprotection.value=='1')
{
document.forms[0].pagecode.value=0;
document.forms[0].act.value='backpressed';
document.forms[0].submit()
}
The above code is working fine for parent window but not if i open child window.
backpressed is keyword am using to check in class file to redirect to page asking username and password. Please help me out in fixing this issue. Thanks in advance
You could add a variable to the session when the child window is loaded and if the user clicks back you would check the session to see if the variable that the child window added to session is nothing inside whichever pages load function and if it is then load normally, if its not redirect to the login page.
OK I'm new to DotNetNuke and need to write a simple module in DNN that will display an article for everyone, and allow the admin to edit the article/add a new one.
I have a test page that contains a DNN module with one module definition and two controls in that definition. The default control shows the article based on an articleID field in the querystring. You then click a button that is supposed to load the edit control and pass the articleID in the query string.
If I use EditURL() in the onClick the edit control is loaded with the correct articleID, but using the admin skin. If I use Globals.NavigateURL() then the correct skin is shown but my edit control isn't loading in the page.
Any clue as to how to what I'm doing wrong or how to get the edit control loading with the correct skin?
My two methods of switching to the edit control (in my button click event) are listed below:
string newURL = this.EditUrl("articleID", Request.QueryString["articleID"], "EditArticle");
Response.Redirect(newURL);
and
string newURL = Globals.NavigateURL(this.TabId, "EditArticle","articleID="+Request.QueryString["articleID"]);
Response.Redirect(newURL);
Actually you are doing this correctly - the editurl in DNN does load the Admin skin - usually this skin is based on someone administering content so it strips out all other modules and shows the 'basics'. Right or wrong this is what it does.
If you dont want to to do that you could provide a switch in the querystring and show a seperate panel or do a multiview control and show different views based on the switch in the query string.
There are a few other approaches like changing the content area to editing text area with ajax or using popup modal style windows.
From what I've already read this appears to be impossible, but I wanted to see if anyone out there has a secret trick up their sleeve or at least a definitive "no".
Supposedly a master page is really just a control for a content page to use, not actually the "master" of a content page. If I wanted to go from one content page, to another content page with the same master page, I would just say
Response.Redirect("PageB.aspx");
But this would immediately cause a postback, flickering the page, which is the crappy pre-ajax way of doing things.
In this current project, I'm trying to see if I could figure out how to change the current content page of a ContentPlaceHolder in the master page asynchronously, when a button is clicked on the master page.
Is this possible, if so how?
I don't know if you can between pages (.aspx) but it can definitely be done using UserControls.
ASP.Net pages each have their own URL so what you're trying to do is to go from one URL to another without any postback, that's just not how it's supposed to work.
Using user controls (.ascx):
Create a page that uses the MasterPage and use something like this in the content
<ajax:UpdatePanel ...>
<ContentTemplate>
<asp:PlaceHolder ...>
</ContentTemplate>
</ajax:UpdatePanel>
Search for UpdatePanel and tweak its settings to do what you want, then learn how to swap user controls in a placeholder.
No, you cannot because a master page is actually a control rendered on a particular aspx page, rather than actually containing the aspx page as it deceptively appears to be programmatically and in design view.
More Info:
You could however use a variety of other controls to simulate this effect. The asp:MultiView control is one example, each "page" could be made in a single view and placed in an update panel, thus allowing it to be switched asynchronously. Alternatively you could define each page in a separate user control and put those in an update panel, asynchronously switching the visible property on those controls as needed.
There are really a lot of different ways to achieve an effect similar to changing the master page's content placeholder.