I found the similar questions how to call java script function from activex or dll in c# but this is not provide me solution.than i continue my searching finally i got msdn link on this
http://msdn.microsoft.com/en-us/library/ms171712.aspx
To access DOM from a UserControl hosted in Internet Explorer
Create your own custom derived class of the UserControl class. For more information, see How to: Author Composite Controls.
Place the following code inside of your Load event handler for your UserControl:
HtmlDocument doc = null;
private void UserControl1_Load(object sender, EventArgs e)
{
if (this.Site != null)
{
doc = (HtmlDocument)this.Site.GetService(typeof(HtmlDocument));
}
}
Unfortunately I am still unable to get DOM object in my class.I have try to see what i get in this.Site so i put it on a messagebox
MessageBox.Show(this.Site.ToString());
which shows me strange thing that is
System.Windows.Forms.Control+AxSourcingSite
please help me..
Related
I Seem to be unable to read HTML after a WPF web browser control has finished navigating to a page.
The reason I have to use a WebBrowser instead of a HttpClient, is because the required web page requires logging into first.
XAML:
<WebBrowser x:Name="wbBrowse" Source="anywebpage" LoadCompleted="wbBrowse_LoadCompleted">
</WebBrowser>
Code:
private void wbBrowse_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
var doc = wbBrowse.Document;
}
I've tried casting Document to HtmlDocument but it crashes. It's a '{System.__ComObject}' object which means nothing to me.
Thanks
Add a reference to Microsoft HTML Object Library under Project->Add Reference->COM in Visual Studio and cast the value of Document to an MSHTML.IHTMLDocument2:
private void wbBrowse_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
MSHTML.IHTMLDocument2 doc = wbBrowse.Document as MSHTML.IHTMLDocument2;
...
}
This does work in .NET Core 3.1.
This question already has an answer here:
Show an HTML file of my Project in WebBrowser control at run-time
(1 answer)
Closed 3 years ago.
I'm working on a Winforms project and want to display the About page content from an HTML file.
I used the WebBrowser control for that but even though it works, I still get the following error message upon opening the solution or building the project:
Error Message
Is there any way to fix it or ignore it?
Here's the method call from the About page class:
private void displayAboutContent()
{
this.labelVersion.Text = string.Format(#"Version: {0}",BoostEngine.r_CurrentVersion);
UITools.displayHTMLPage(m_WebBrowser, m_ResourceName);
}
and the UI Tools static class:
public static class UITools
{
public static void displayHTMLPage(WebBrowser i_WebBrowser, string i_ResourceName)
{
Uri uri = new Uri(getFilepath(i_ResourceName));
i_WebBrowser.ScriptErrorsSuppressed = true;
i_WebBrowser.Navigate(uri);
}
private static string getFilepath(string i_ResourceName)
{
string projectPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
string filePath = Path.Combine(projectPath, string.Format("Resources\\{0}.html", i_ResourceName));
return filePath;
}
}
P.S.
I'm using this code on another form but receive the error only for the About page.
Also important to note, I'm using a Parallels VM on Mac.
Thanks!
I don't know what is running code during solution load or compile, you might look in your project file for any targets that have been added.
But to simply get around the problem you could choose to not Navigate if the file doesn't exist:
if(System.IO.File.Exists("c:\\whatever"))
{
i_WebBrowser.Navigate(uri);
}
If you do that you might consider loading a page that is guaranteed to be there or load a string of html to make it a little more user friendly with an appropriate message.
I am trying to build a simple Python Editor with ScintillaNET and am now trying to return the input.
I have a class PythonScriptView:
public class PythonScriptView : Scintilla
{
// setup python syntax highlighting
}
and a Form which consists of a PythonScriptView component and an OK button. Inside this class I want to build a function which shows the form and returns the Text property of my PythonScriptView. I did this for another small dialog window which uses a textbox as input field and are now trying the same with the scintilla editor:
public string GetUserInput()
{
ShowDialog();
return ScriptView.Text; // ScriptView is of Type PythonScriptView
}
When I am running the app I get the following error message:
An unhandled exception of type 'System.AccessViolationException' occurred in ScintillaNET.dll
Does anyone know how to solve this? How else can I read the Text property?
Edit:
Seems like I cannot access any properties or methods from this class
I was having this same issue and it appears that due to the way ScintillaNET works you are not able to access any properties once the element is disposed do to the form closing. I found a work around by adding the following event and property to my Form.
private void FormClosing(object sender, FormClosingEventArgs e)
{
CachedText = scintilla.Text;
}
public string CachedText { get; private set; }
I tried and tried, looked here, on Google and didn't find how to do it. I just try to write a simple user control (.ascx) to display different type of ads (which all of them are scripts). The problem is that usually it's a complicated scripts, so someone (here) suggested to save the scripts as .JS files and call them from the control (.ascx) file. The question: How do I do it? Tried lot of time and it's not work. I'm frustrated...
Can anyone pls give me an example code of how to do it?
Thanks a lot!
You can attach that "script file" to the page from the User Control using something like this:
(Taken from here in MSDN
public void Page_Load(Object sender, EventArgs e)
{
// Define the name, type and url of the client script on the page.
String csname = "ButtonClickScript";
String csurl = "~/script_include.js";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the include script exists already.
if (!cs.IsClientScriptIncludeRegistered(cstype, csname))
{
cs.RegisterClientScriptInclude(cstype, csname, ResolveClientUrl(csurl));
}
}
This way you include your script file with the correct url into the page. Then will load on client side, and assuming you have written everything correctly, will perform as intended.
I am using DNN6 and i creted two modules and tried to connect between them using module communicator, here is my code:
#region IntermoduleCommunication
ModuleCommunicationEventArgs oArgs = new ModuleCommunicationEventArgs();
oArgs.Value = Session["ShoppingCart"];
if (ModuleCommunication != null)
ModuleCommunication(this, oArgs);
#endregion
but i am getting 'null' in the ModuleCommunication variable?
Are you wrapping the modules in an update panel, (have the supports partial rendering option enabled) in the DNN manifest?
If I recall correctly, IMC won't work via UpdatePanels.
From whatever code you have provided, it should work. In order to get help you need to provide code for both IModuleCommunicator and IModuleListener implementation. But you can review Example implementation here. Let me know if you need more help.
Also if you are not using latest version of dnn, please try testing it by creating of latest dnn instance. Let me know if you need more help.
To get this working you need to implement the IModuleCommunicator interface. Right click on the IModuleCommunicator as showed below and extract the interface.
public partial class MyClass: PortalModuleBase, IModuleCommunicator
once extracted the following will be generated
public event ModuleCommunicationEventHandler ModuleCommunication;
I call it from a button click event
protected void btn1_Click(Object sender, EventArgs e)
{
if (ModuleCommunication == null) return;
ModuleCommunicationEventArgs args = new ModuleCommunicationEventArgs();
args.Sender = this.GetType().ToString(); ;
args.Target = "MyTarget";
}
wrap the whole thing in a try catch block to catch exceptions......hope this helps
The answer here is simple, you've forgotten exactly how events work, they are just like any other object, you have to instantiate them. aka.
public event ModuleCommunicationEventHandler ModuleCommunication = new ModuleCommunicationEventHandler(SomeStaticMethodThatWillBeCalledByDefault);