C# web browser tab text - c#

Hello i have been creating a web browser for college. The problem that i have that is driving me insane is trying to get current web browser page i am ons text in the tab like if i am on Google i would like to say it in the tab.
i tried
private void addTextImageTab()
{
try
{
mainBrowserTC.SelectedTab.Text = getCurrentWB().Document.Url.ToString();
}
catch
{
MessageBox.Show("Error");
}
}
and my getCurrentWB() method is
private WebBrowser getCurrentWB()
{
return (WebBrowser)mainBrowserTC.SelectedTab.Controls[0];
}
Every time i try to run it it crashes i tried every thing that i know and search the web the last few days and could find a solution please help.

Related

How do I Display a Message across projects?

We have one Visual Studio 2019 ASP.NET solution with 22 projects, one of which is called BusinessLogic and one which is called Web.
In BusinessLogic, we have code to log errors, and it used by all projects in the solution.
public static Guid? StartDebugLog(String module, String method, String message)
{
if (ApplicationSettings.IsDebugLogActive)
{
using (BPIContext context = SessionManager.CreateNewBPIContext)
{
DebugLog debugLogObject = new DebugLog();
debugLogObject.ID = Guid.NewGuid();
debugLogObject.Module = module;
debugLogObject.Method = method;
debugLogObject.StartTime = DateTime.Now;
if (message == null)
debugLogObject.Message = "(NULL)";
else
debugLogObject.Message = message;
context.AddToDebugLog(debugLogObject);
context.SaveChanges();
return debugLogObject.ID;
}
}
return null;
}
The problem is that this routine is hiding important errors from our customers. Yes, they can go into the application logs, but simply starting the application creates over 100 entries in the application log. Finding errors would be a daunting task to ask of our customers.
I need a way for this routine to be able to display a basic message so that customers do not continue on, thinking everything is OK. Something like alert("An error has occurred."), but the *BusinessLogic project does not have access to the Web project.
Is there a recommended way to create a CALLBACK or something? Most of my background is in Windows Forms where this would be simple. Something like this:
...
context.AddToDebugLog(debugLogObject);
context.SaveChanges();
if (WebCallback != null)
{
WebCallback(debugLogObject);
}
return debugLogObject.ID;
...
I'm not even sure if this is possible in a Web environment. If it is not possible, that's an answer too.
For a "Part 2", some of our newer modules are displayed by dropping them into an iFrame. Is there a way to create something that will allow information from the iFrame to pass to the parent? Currently, all messages that are sent in the iFrame appear to get lost.

Selecting web element with id in appium test started using AndroidDriver

I'm new to Appium and testing as a whole. I used Android driver to test an app in android.
I can handle all clicks and typing in the app. But the issue arises while using the OAuth service to log in the app.
I use the following Driver client. appium dotnet driver
The login service opens in a separate chrome browser. I have to type text in an input element inside the web page.
I use the following code. On debugging page resource only has the android elements of the chrome browser and nothing of the web content.
var appiumDriver = new AndroidDriver<AndroidElement>(driverUri, appiumOptions);
[Test()]
[Order(1)]
public async Task TestLogin()
{
try
{
appiumDriver.FindElementByAccessibilityId("Login").Click();
await Task.Delay(3000);
var source = appiumDriver.PageSource;
var element = appiumDriver.FindElementById("login-email");
}
catch (NoSuchElementException ex)
{
}
}
Can anyone suggest how to proceed with this problem? This also has to be done in iOS, I guess both can be handled the same way.. Thanks in advance.
The issue was not changing to web context for searching in web page. The test flow had to be
Perform action to open the web page from the app. (In my case clicking login button)
Wait till the web page appears. (This is important as the web context will be available only after the web page appears) For this, I used a FindElementByClassName for a unique control visible in the web page but not on the previous App page. There sure can be a better way.
Get available contexts and switch to web context.
I used FindByCssSelector for finding the element with id.
Changing to web context
public static void ChangeToWebContext()
{
if (driver.Context != "NATIVE_APP")
return;
var elements = driver.FindElementByClassName("android.widget.EditText");
var availableContext = driver.Contexts;
if (availableContext.Count >= 2)
{
driver.Context = availableContext[1];
return;
}
}
Usgae:
this.ChangeToWebContext();
driver.FindElementByCssSelector("#login-password");

How to use Skin.AddPageMessage() method?

I am developing a DNN module and I want to display an info message at the top of my ContentPane, not above the actual module. I have found that DotNetNuke.UI.Skins.Skin.AddPageMessage() should just do the thing. I am not getting the behavior I want though, the message just won't display at all.
There are few overloads of this method, one group accepting a Page object, the other one taking a Skin object.
public static void AddPageMessage(Page page, string heading, string message, ModuleMessage.ModuleMessageType moduleMessageType)
public static void AddPageMessage(Skin skin, string heading, string message, ModuleMessage.ModuleMessageType moduleMessageType)
I did take a look into the DNN source and found out that in the end they're actually using the same private static AddPageMessage(...) method, which just looks for a ContentPane within the provided control and adds a new ModuleMessage to the collection of its controls.
What should I pass as a Page or Skin parameter to get this correclty working?
Thanks ...
The private AddPageMessage method takes a fairly ambiguous "Control" as the first parameter. I believe that needs to be the current Skin, as it does a FindControl for ContentPane.
Doing something like this should get you a reference to the current skin:
var skin = Skin.GetSkin((PageBase)this.Page);
Skin.AddPageMessage(skin, "Header", "Message", ModuleMessageType.GreenSuccess);
the reason why the messages are not showing up is that you turned on "enable partial rendering" in the controlssetting of the modulecontrols.
If you are using AJAX (this is happening if you set the partial rendering to true) the DNN modulemessages are turned off from DNN itselfe.
Its enough if you have turned the partial rendering on just 1 control (dont have to be your control where you are acting from) on your page. DNN will wrap the whole page into ajax script manager and messages are not working anymore.
*EDIT 26.04.2012 10:45:
You can get the current ScriptManager by executing the following Code for example in you Page_Load(). If the manager is null, you dont have ajax enabled and the modulemessages should work. If bIsAjaxEnabled is true the modulemessages are disabled.
ScriptManager manager = AJAX.GetScriptManager(Page);
if (manager != null)
{
bool bIsAjaxEnabled = manager.SupportsPartialRendering;
}

AjaxMethods in Windows Azure not working

We are showing reports in our Azure web application using ReportViewer (rdlc) control in VS2010 which is working perfectly. Recently my client asked me to capture the the Print event for ReportViewer and log an entry on the server. I've hooked the with the print button.. This works perfectly when I run the web application on a local environment. However, on Azure, the Ajax method never gets called from client side. Please suggest what to do? Is there a limitation for Ajax in Azure Environment?
I'm registering the Page on Page_Load in code behind
protected void Page_Load(object sender, EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(Pages.Report));
ImageButton btnPrint = new ImageButton();
btnPrint = ((ImageButton)(this.FindControl("ctl00$" + ReportViewer1.ClientID.Replace("_","$") + "$ctl06$ctl06$ctl00$ctl00$ctl00")));
btnPrint.Attributes["onclick"] += "attachEventForPrint();";
}
[AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public static void LogEvent(int pLoggingEvent)
{
// Addded logic to log event
}
And in ASPX file following function was added in JS
function attachEventForPrint() {
if (typeof (Report) != "undefined") {
Report.LogEvent(4);
}
}
The good news is that I don't think there's any limitation with using ajax controls - I've used a few and they just worked.
Some things to check might be:
can you use Fiddler to view the HTTP trace - is a request being sent to the server when you click on the the print button?
can you use a javascript debugger to check that there are no errors being reported when attachEventForPrint occurs?
are there any issues here with "State" - especially with Session storage?
One other thing to check is whether there is a more maintainable way to access the print button - the "$ctl06$ctl06$ctl00$ctl00$ctl00" just looks like it is asking for trouble either now or at some point in the future

Enable DOM Access for Silverlight Web Part in Sharepoint 2010

I am hosting a silverlight 3.0 control on my Sharepoint 2010 page. I am using the built-in SilverlightWebPart web part, where I have provided the path for .xap file.
Its displaying properly, but when I try to access the System.Windows.Browser, its throwing an error. My code is:
public static string GetQueryString(string key)
{
try
{
var documentQueryString = (Dictionary<string, string>)System.Windows.Browser.HtmlPage.Document.QueryString;
if (documentQueryString.ContainsKey(key))
{
return documentQueryString[key].ToString();
}
}
catch (Exception ex)
{
return ex.Message;
}
return string.Empty;
}
The error I am getting is: The DOM/scripting bridge is disabled. How do I enable this? I know if I host this in a ASP.NET page, I can add the param - <param name="enablehtmlaccess" value="true"/>. I have tried putting this webpart in a "content editor web part", and I have embedded the object tag to call the .xap file and its working totally fine. I need to make it work using the built-in Silverlight web part.

Categories

Resources