Issue while enabling hyperlinks in master page from content page - c#

I had written code to Enable and disable hyperlinks on master page from the content page. Every thing is working fine and the hyperlinks are getting disabled also after calling the DisableHyperlinkInMasterPage Method. When i am calling the EnableHyperlinkInMasterPage method still the hyperlinks are not working. If we are leaving that page , then i found that the hyperlinks starts working. My issue is after calling the EnableHyperlinkInMasterPage method , without leaving the page the hyperlinks are still disabled and not working and after leaving the page it getting enabled . Please help me that how i fix this issue.I debug the code and not found any error on EnableHyperlinkInMasterPage method.
private void DisableHyperlinkInMasterPage()
{
AssociateMaster mymaster = (AssociateMaster)Page.Master;
HyperLink home = (HyperLink)mymaster.FindControl("Home");
home.Enabled = false;
HyperLink profile = (HyperLink)mymaster.FindControl("ProfileLink");
profile.Enabled = false;
HyperLink report = (HyperLink)mymaster.FindControl("Report");
report.Enabled = false;
HyperLink signout = (HyperLink)mymaster.FindControl("SignOut");
signout.Enabled = false;
}
private void EnableHyperlinkInMasterPage()
{
AssociateMaster mymaster = (AssociateMaster)Page.Master;
HyperLink home = (HyperLink)mymaster.FindControl("Home");
home.Enabled = true;
HyperLink profile = (HyperLink)mymaster.FindControl("ProfileLink");
profile.Enabled = true;
HyperLink report = (HyperLink)mymaster.FindControl("Report");
report.Enabled = true;
HyperLink signout = (HyperLink)mymaster.FindControl("SignOut");
signout.Enabled = true;
}

Try using properties to enable and disable links. And try using FindControl as less as you can. Consider you have a link in your MasterPage named lnkTest. Write this code in your master page:
public bool TestLinkEnabled
{
get { return lnkTest.Enabled; }
set {lnkTest.Enabled = value; }
}
Then in your content page after adding this line to your page:
<%# MasterType VirtualPath="~/MasterPage.master" %>
enable and disable this link using:
Master.TestLinkEnabled = true;
Master.TestLinkEnabled = false;

Related

Webpage pops out of webview in Xamarin App

When loading a webpage into the webview it shows correctly, but when I click on a menu item (on the web page inside the webview) it pops outside of the webview. Here is the code I'm using to load the webpage into the webview. How do I prevent this from happening.
BTW, the links are all normal links:
Menu Item
localWebView = FindViewById<WebView>(Resource.Id.webview);
localWebView.Settings.JavaScriptEnabled = true;
localWebView.Settings.JavaScriptCanOpenWindowsAutomatically = true;
localWebView.Settings.LoadWithOverviewMode = true;
localWebView.Settings.UseWideViewPort = true;
localWebView.Settings.BuiltInZoomControls = true;
localWebView.LoadUrl("https://...");
I needed to add a WebViewClient and it works now.
localWebView.SetWebViewClient(new MyWebViewClient());
public class MyWebViewClient : WebViewClient
{
[Obsolete("deprecated")]
public override bool ShouldOverrideUrlLoading(WebView view, string url)
{
view.LoadUrl(url);
return true;
}
}

How do I have master details page and a back button on single page

I have app where in I have master details page something like this:
I would have this(left menu bar settings, login) static for all the pages. Since I am using master details page I am using messagingcenter to navigate between pages as given here:
MessagingCenter.Send(new RedirectClass.OpenDetails(), RedirectClass.OpenDetails.Key);
But now since I have used master details I cannot navigate back using back button. The back button would exit the application. Say user is at 'page A', When user clicks on settings menu the user should be redirected to settings page(settings page will all have left menu), so on click of back button on settings page should redirect user to 'Page A'. Which is not happening. ANy help?
MessagingCenter.Subscribe<RedirectClass.OpenDetails>(this, RedirectClass.OpenDetails.Key, (sender) =>
{
Detail = new NavigationPage(new Details())
{
BarBackgroundColor = Color.FromRgb(172, 183, 193),
BarTextColor = Color.Black,
BackgroundColor = Color.White
};
});
Instead of overriding the Detail page in your MessagingCenter callback
Detail = new NavigationPage(new Details())
You should use the Detail page's Navigation property to push the new page on the top of the stack
Detail.Navigation.PushAsync(new Details())
make sure your initial detail page is wrapped in a navigationpage
I was having same issue, Detail.Navigation.PushAsync(itemSelected) makes hamburger menu vanish I decided to use my own stack datatype for Master detail page. It was bit tricky to keep track and code but working fine.
Initialize it at the app load with current Detail page and for each item selected Push new page on top of stack.
public partial class MyMasterDetailPage: MasterDetailPage
{
private Stack navigationStack = new Stack();
public MyMasterDetailPage()
{
InitializeComponent();
navigationStack.Push(Detail);
try
{
masterPage.listView.ItemSelected += OnItemSelected;
}
catch (Exception exc)
{
System.Diagnostics.Debug.WriteLine(exc.Message);
}
}
Override OnBackButtonPressed() in same Page code behind
protected override bool OnBackButtonPressed()
{
try
{
var lastPage = navigationStack.Pop();
if (lastPage.Equals(Detail))
lastPage = navigationStack.Pop();
Detail = (Page)lastPage;
IsPresented = false;
// to avoid app close when complete pop and new page is push on top of it
if (navigationStack.Count == 0)
navigationStack.Push(Detail);
return true;
}
catch (Exception)
{
return base.OnBackButtonPressed();
}
}

Access master page control not work

I work with a master page in which there is one HyperLink. I set that HyperLink NavigateUrl form (master page's) child page.
for that i use this code in child page.
HyperLink hl = (HyperLink)this.Master.FindControl("linkviewmysite");
hl.NavigateUrl = "../" + ds.Tables[0].Rows[0]["username"].ToString();
Response.Redirect("Siteadmindata.aspx", false);
here linkviewmysite is the id of master page's HyperLink.
now problem is when i set NavigateUrl it's not work.
But when is remove this line (Response.Redirect("Siteadmindata.aspx", false);) from code than navigateurl set and HyperLink is work fine for me.
so now what should i do for it with Response.Redirect.
i got the answer
HyperLink hl = (HyperLink)this.Master.FindControl("linkviewmysite");
session["user_name"] = ds.Tables[0].Rows[0]["username"].ToString();
Response.Redirect("Siteadmindata.aspx", false);
now in master page page load
if(!postback)
{
if(session["user_name"]!=null)
{
linkviewmysite.navigationurl="../"+session["user_name"].tostring();
}
}

How call GetWebResourceUrl() when Page is null ?

I built custom ASP.NET control and it's working fine when I add it manually (drag and drop) or by code to controls in markup.
The custom control, MsgBox, had resources like JavaScript, CSS and images embedded in and the problem appeared when I tried to Render the control in class to return its HTML code, the Page instance is null and the "GetWebResourceUrl" needs it:
Page.ClientScript.GetWebResourceUrl(.....)
is there any way to get the resourceurl ? Here is my render code:
protected override void RenderContents(HtmlTextWriter writer)
{
using (PlaceHolder plh = new PlaceHolder())
{
if (Page != null)
{
if (DesignMode || Page.Header == null)
RegisterCSSInclude(plh);
}
HtmlGenericControl container = new HtmlGenericControl("div");
container.EnableViewState = false;
container.InnerHtml = "Control html code";
plh.Controls.Add(container);
plh.RenderControl(writer);
}
}
RegisterCSSInclude is method to register my css files:
private void RegisterCSSInclude(Control target)
{
// CSS
bool linkIncluded = false;
foreach (Control c in target.Controls)
{
if (c.ID == "MsgBxStyle")
{
linkIncluded = true;
}
}
if (!linkIncluded)
{
HtmlGenericControl globalCsslink = new HtmlGenericControl("link");
globalCsslink.ID = "MsgBxGStyle";
globalCsslink.Attributes.Add("href", Page.ClientScript.GetWebResourceUrl(typeof(MessageBoxCtrl), "MessageBox.MsgBxStyles.WeDevMsgBox.css"));
globalCsslink.Attributes.Add("type", "text/css");
globalCsslink.Attributes.Add("rel", "stylesheet");
globalCsslink.EnableViewState = false;
target.Controls.Add(globalCsslink);
HtmlGenericControl csslink = new HtmlGenericControl("link");
csslink.ID = "MsgBxStyle";
csslink.Attributes.Add("href", Page.ClientScript.GetWebResourceUrl(typeof(MessageBoxCtrl), "MessageBox.MsgBxStyles." + Style.ToString().ToLower() + ".css"));
csslink.Attributes.Add("type", "text/css");
csslink.Attributes.Add("rel", "stylesheet");
csslink.EnableViewState = false;
target.Controls.Add(csslink);
}
}
Update:
PS: I'm tring to use control in generic handler (ashx) where I call ShowMsgBox method which is a method in a class and not in a page or user control.
ShowMsgBox method should create an instance of MsgBox control and render it then return the html code to ashx class :
var htmlCode = MyClass.ShowMsgBox("myMsg");
context.Response.write(htmlCode);
I built a custom ASP.NET control ...
I'm tring to use control in generic handler (ashx) ... not in a page or user control.
A Page is a handler. You want to use a convenience provided by the Page class, but you don't want to inherit from Page. The niceties of Page, such as ClientScript, expect a Page from which to get various information.
You can provide a dummy Page object to your control by setting the Page property of your custom Control:
this.Page = new Page();
...then you will need to set various properties (assuming they are public) which are expected by ClientScriptManager.GetWebResourceUrl():
this.Page.Foo = "bar";
then you can call:
this.Page.ClientScript.GetWebResourceUrl(...);
If this is the specific class that inherits from WebControl page shouldn't be null. If its another class that you are rendering as part of a hierarchy you can add a parameter of type Page and pass the reference of the current page to it.

creating RadEditor dynamically asp.net

I want to add RadEditor dynamically. It is getting added to the page but as soon as postback occurs i get Multiple controls with the same ID 'EditorRibbonBarResourcesHolder' were found. Below is the code that i am using to add control dynamically.
RadEditor editor = new RadEditor();
editor.ID = "editor_" + itemTypeattribute.ItemAttributeID + rand.Next();
cellAttributeValue.Controls.Add(editor);
editor.DialogOpener.ID = "editor_dialopOpener_" + itemTypeattribute.ItemAttributeID;
editor.DialogOpener.Window.ID = "editor_dialopOpener_window_"+ ItemTypeattribute.ItemAttributeID;
editor.ClientIDMode = ClientIDMode.AutoID;
editor.EnableEmbeddedScripts = true;
editor.Height = 200;
Any help is appreciated. Thanks
Whenever I need to use a radeditor "dynamically" I have it on the page from the start with visible=false and then show it when I need it.

Categories

Resources