|
<%@ Page Language="C#" %>
string strJS;
private void Page_Load(object sender, System.EventArgs e)
{
// sets the onload event to call setPROCTYPE and provides parameters
strJS = "onload=\"javascript:setPROCTYPE('procedure', 'int');\"";
}
function setPROCTYPE(cmd,type)
{
alert('hello marc...');
parent.process.closeLookUpWin();
setDate();
document.form1.PROCTYPE.value=cmd;
document.form1.DLTYPE.value=type;
}
>
You can also do things like:
((Button) e.Item.FindControl("DeleteButton")).Attributes.Add("onClick", "return confirm('Are you sure you wish to delete this item?');");
Hope this helps,
~Alexander Kent
|
|
|
|
|
When I use the code exactly as provided, I get an error stating that I am referring to an un-instantiated object (Object reference not set to an instance of an object), and if I try to instatiate the object (= new HTMLInputElement) I get COM object with CLSID {xxxxxxxx...} either not valid or not registered.
When I run the pre-compiled demo, google.com loads fine in the window, but no data is entered and no events are processed; I am essentially looking at a basic browser control with a loaded page and nothing more.
I feel like I must be missing something small, but I can't see what it is for the life of me. Could you please point me in the right direction? Thank you very much!
-Andrew
|
|
|
|
|
I wonder what platform you are using? Windows98 maybe?
Also are you using the Visual Studio IDE or the Command line compiler?
AxSHDocVw.dll and SHDocVw.dll?
~Alexander Kent
|
|
|
|
|
Thanks for your email;
Well if myDoc.all.item and Doc.getElementsByName yield no result for the password field, I guess as a quick hack one can always fill in the loginid using the conventional DHTML or DOM method and then use something like
SendKeys.Send("{tab}");
SendKeys.Send("A");
SendKeys.Send("B");
etc to fill in the password field
~Alexander Kent
|
|
|
|
|
This code is cool....
I can get things to work with one page.
But I would like to load more than one page.
@ run code page1
run code on page 2 ect.
I seem to have a problem keeping the browsers display insync
any suggestions
|
|
|
|
|
Hello,
great article. I have a question on finding the HTML element by name using non-alphanumerics. I am trying to get a button named "next >" to click, but the greater than sign is not recognized and my code errors-out. How do you handle these types of characters, because when the button is named "next" (with no greater sign), it works flawlessly.
Thanks.
|
|
|
|
|
Lets say the HTML is like:
<html>
<head>
</head>
<body>
<form name="form1" method="post" action="">
<input name="next >" type="submit" id="next >" value="Submit">
</form>
</body>
</html>
Then your C# code:
HTMLDocument myDoc = new HTMLDocumentClass();
myDoc = (HTMLDocument) axWebBrowser1.Document;
HTMLInputElement btnNext = (HTMLInputElement) myDoc.all.item("next >",0);
btnNext.value = "gotcha";
btnNext.click();
I haven’t tested this but I am sure this should work just fine, don’t use myDoc.all.item("next >",0); or any fancy CDATA Hope this helps,
~Alexander Kent
|
|
|
|
|
I'd like a couple of buttons instead of using the traditional scroll bars, how can I get the webbrowser to scroll up and down as needed.
Thanks
Carmen Branje
|
|
|
|
|
I see in your example (great article BTW), that you use the IHTMLElementCollection.index(object name, object index) method and you get an element by its name. I am trying to get an element by its index and I can't figure out the right args to use. I am able to iterate over the collection using the IEnumerator interface supported, but in my case, I just want to get the nth element since the elements do not have IDs. I tried this syntax:
children.item(null, n);
but this always seems to return the 0th element in the collection. Any thoughts on this?
Thanks,
Pete
|
|
|
|
|
try to:
children.item(n,0);
bye
|
|
|
|
|
Does anyone have some good advice or examples of how to do this using vb.net?
I'm trying enter a login and password input fields automatically.
I am more comfortable coding in VB and would like to do something similar to the above topic. Any help would be great. Thanks in advance!
|
|
|
|
|
' add reference to Microsoft HTML
' Imports mshtml
' Form load
AxWebBrowser1.Navigate2("http://somewhere.com")
' Document Complete...
Dim myDoc As mshtml.HTMLDocument = AxWebBrowser1.Document
myDoc.all.item("loginid", 0).value = "fsdfsdgsgd"
~Alexander Kent
|
|
|
|
|
is there a way to simulate hyperlink clicks? for example clicking on the "Images" link? how can u find them in the doc when they don't have an object name????
|
|
|
|
|
I don't know if this will help, but did you try using the links property of the HTMLDocument ? It looks like you can access them by index. Then, once you have an HTMLLinkElement , you can call its click() method. This article looks useful-- I haven't had a chance to play with this stuff yet.
Regards,
Jeff Varszegi
EEEP! An Extensible Expression Evaluation Package
|
|
|
|
|
You first have to cast to an IHTMLElement , which declares the click method.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Could someone inform me on how to control popup boxes that some web pages load. "confirm" popup
I would just like to know how to get it to Automaticaly click the OK button.
Thanks.
|
|
|
|
|
Not sure what you are referring to - but "click the OK button" sounds like Win32 API may do it; see
Gunnar's Question
|
|
|
|
|
You may take a look at
NetRix HTML Editor control
which has much more editing functions and additional features for accessing DHTML events.
Joerg
|
|
|
|
|
HTTP Error 404 - File or directory not found
My C#, My love
|
|
|
|
|
|
Alexander,
Thanks for the code, I used it to do a quick and easy HTML help file. Good work.
Joe
|
|
|
|
|
Do you know how to get the web browser control to support XP themes. Notice in your Google screenshot for example that the text input field and buttons are bevelled.
Interestingly, I've also found that when I add the browser control to an existing form that did support themes (via System.Windows.Forms.Application.EnableVisualStyles()), the controls revert back to old style.
I have been searching high and low for a way to get this to work but to no avail. Any ideas would be greatly appreciated.
|
|
|
|
|
Try using a manifest file and flag your controls to version 6 upwards.
I think the Application.EnableVisualStyles might be a bit problematic in dotnet where it has to have DoEvents or something called.
Hope this helps
|
|
|
|
|
I have found a couple of solutions to this problem.
The simple solution is to add a meta tag to your HTML:
Unfortunately, this only works if you have control over the HTML.
The more complicated solution involves writing a custom ATL COM component in managed C++ that implements the IDocHostUIHandler and IOleClientSite COM interfaces. Within this you need to specify that themes are supported, which they are not by default:
HRESULT STDMETHODCALLTYPE GetHostInfo(/* [out][in] */ DOCHOSTUIINFO *pInfo)
{
pInfo->dwFlags = DOCHOSTUIFLAG_THEME;
return S_OK;
}
This component is connected to the web browser control in the class that contains the control:
MyHtmlHost uiHandler = new MyHtmlHost(this.axWebBrowser1, null);
|
|
|
|
|
You've just solved my problem, so by way of thanks I'll make your life easier. You don't have to go through the agonies of C++ to implement GetHostInfo, you can do it in a method of your winform, all you need is the interfaces. I have included at the end of this posting my complete interfaces file that I partly wrote myself and mostly pillaged from the efforts of others. Alas their names are not in the code. It never occurred to me that I might be the one providing help, and I rewrote it to improve the coherence of style, but they were many and if any of you recognise your own work then tell me and I'll rectify the omission of your credit.
These interfaces will put you in a position to seriously yank the chain of MSHTML. For example once you have the interface declared correctly it is a piece of cake to return any C# object as the result of IDocHostUIHandler.GetExternal() which is how I bind events in generated UI back to event handlers implemented in C# in the host form.
You're quite right - there's not a single comment in the whole damn thing. I wrote it for me, not for you. And all of these interfaces are completely documented in this Microsoft tutorial on the subject.[^]
<button onclick="window.external.AddNew('tableX')">Add New X</button>
using System;
using System.Windows.Forms;
using mshtml;
using SHDocVw;
using System.Runtime.InteropServices;
namespace BrowserCustomisation {
#region IDocHostUIHandler
public enum DOCHOSTUITYPE {
DOCHOSTUITYPE_BROWSE = 0,
DOCHOSTUITYPE_AUTHOR = 1
}
public enum DOCHOSTUIDBLCLK {
DOCHOSTUIDBLCLK_DEFAULT = 0,
DOCHOSTUIDBLCLK_SHOWPROPERTIES = 1,
DOCHOSTUIDBLCLK_SHOWCODE = 2
}
public enum DOCHOSTUIFLAG {
DOCHOSTUIFLAG_DIALOG = 0x00000001,
DOCHOSTUIFLAG_DISABLE_HELP_MENU = 0x00000002,
DOCHOSTUIFLAG_NO3DBORDER = 0x00000004,
DOCHOSTUIFLAG_SCROLL_NO = 0x00000008,
DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE = 0x00000010,
DOCHOSTUIFLAG_OPENNEWWIN = 0x00000020,
DOCHOSTUIFLAG_DISABLE_OFFSCREEN = 0x00000040,
DOCHOSTUIFLAG_FLAT_SCROLLBAR = 0x00000080,
DOCHOSTUIFLAG_DIV_BLOCKDEFAULT = 0x00000100,
DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY = 0x00000200,
DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY = 0x00000400,
DOCHOSTUIFLAG_CODEPAGELINKEDFONTS = 0x00000800,
DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8 = 0x00001000,
DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 = 0x00002000,
DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE = 0x00004000,
DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION = 0x00010000,
DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION = 0x00020000,
DOCHOSTUIFLAG_THEME = 0x00040000,
DOCHOSTUIFLAG_NOTHEME = 0x00080000,
DOCHOSTUIFLAG_NOPICS = 0x00100000,
DOCHOSTUIFLAG_NO3DOUTERBORDER = 0x00200000,
DOCHOSTUIFLAG_DELEGATESIDOFDISPATCH = 0x00400000
}
[ StructLayout( LayoutKind.Sequential )]
public struct DOCHOSTUIINFO {
public uint cbSize;
public uint dwFlags;
public uint dwDoubleClick;
[MarshalAs(UnmanagedType.BStr)] public string pchHostCss;
[MarshalAs(UnmanagedType.BStr)] public string pchHostNS;
}
[StructLayout( LayoutKind.Sequential )]
public struct tagMSG {
public IntPtr hwnd;
public uint message;
public uint wParam;
public int lParam;
public uint time;
public tagPOINT pt;
}
[ComImport(),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
GuidAttribute("bd3f23c0-d43e-11cf-893b-00aa00bdce1a")]
public interface IDocHostUIHandler {
[PreserveSig]
uint ShowContextMenu(uint dwID, ref tagPOINT ppt,
[MarshalAs(UnmanagedType.IUnknown)] object pcmdtReserved,
[MarshalAs(UnmanagedType.IDispatch)] object pdispReserved);
void GetHostInfo(ref DOCHOSTUIINFO pInfo);
void ShowUI(uint dwID, ref object pActiveObject, ref object pCommandTarget, ref object pFrame, ref object pDoc);
void HideUI();
void UpdateUI();
void EnableModeless(int fEnable);
void OnDocWindowActivate(int fActivate);
void OnFrameWindowActivate(int fActivate);
void ResizeBorder(ref tagRECT prcBorder, int pUIWindow, int fRameWindow);
[PreserveSig]
uint TranslateAccelerator(ref tagMSG lpMsg, ref Guid pguidCmdGroup, uint nCmdID);
void GetOptionKeyPath([MarshalAs(UnmanagedType.BStr)] ref string pchKey, uint dw);
object GetDropTarget(ref object pDropTarget);
[PreserveSig]
void GetExternal([MarshalAs(UnmanagedType.IDispatch)] out object ppDispatch);
[PreserveSig]
uint TranslateUrl(uint dwTranslate,
[MarshalAs(UnmanagedType.BStr)] string pchURLIn,
[MarshalAs(UnmanagedType.BStr)] ref string ppchURLOut);
IDataObject FilterDataObject(IDataObject pDO);
}
[ComImport(),
GuidAttribute("3050f6d0-98b5-11cf-bb82-00aa00bdce0b")]
public interface IDocHostUIHandler2: IDocHostUIHandler {
void GetOverrideKeyPath([MarshalAs(UnmanagedType.BStr)] ref string pchKey, uint dw);
}
#endregion
#region IDocHostShowUI
[ComImport,
Guid("C4D244B0-D43E-11CF-893B-00AA00BDCE1A"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown) ]
public interface IDocHostShowUI {
[PreserveSig]
uint ShowMessage(IntPtr hwnd,
[MarshalAs(UnmanagedType.BStr)] string lpstrText,
[MarshalAs(UnmanagedType.BStr)] string lpstrCaption,
uint dwType,
[MarshalAs(UnmanagedType.BStr)] string lpstrHelpFile,
uint dwHelpContext,
out int lpResult);
[PreserveSig]
uint ShowHelp(IntPtr hwnd, [MarshalAs(UnmanagedType.BStr)] string pszHelpFile,
uint uCommand, uint dwData,
tagPOINT ptMouse,
[MarshalAs(UnmanagedType.IDispatch)] object pDispatchObjectHit);
}
#endregion
#region IOleClientSite
[ComImport,
Guid("00000118-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleClientSite {
void SaveObject();
void GetMoniker(uint dwAssign, uint dwWhichMoniker, ref object ppmk);
void GetContainer(ref object ppContainer);
void ShowObject();
void OnShowWindow(bool fShow);
void RequestNewObjectLayout();
}
#endregion
#region IOleObject
[ComImport,
Guid("00000112-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleObject {
void SetClientSite(IOleClientSite pClientSite);
void GetClientSite(ref IOleClientSite ppClientSite);
void SetHostNames(object szContainerApp, object szContainerObj);
void Close(uint dwSaveOption);
void SetMoniker(uint dwWhichMoniker, object pmk);
void GetMoniker(uint dwAssign, uint dwWhichMoniker, object ppmk);
void InitFromData(IDataObject pDataObject, bool fCreation, uint dwReserved);
void GetClipboardData(uint dwReserved, ref IDataObject ppDataObject);
void DoVerb(uint iVerb, uint lpmsg, object pActiveSite, uint lindex, uint hwndParent, uint lprcPosRect);
void EnumVerbs(ref object ppEnumOleVerb);
void Update();
void IsUpToDate();
void GetUserClassID(uint pClsid);
void GetUserType(uint dwFormOfType, uint pszUserType);
void SetExtent(uint dwDrawAspect, uint psizel);
void GetExtent(uint dwDrawAspect, uint psizel);
void Advise(object pAdvSink, uint pdwConnection);
void Unadvise(uint dwConnection);
void EnumAdvise(ref object ppenumAdvise);
void GetMiscStatus(uint dwAspect,uint pdwStatus);
void SetColorScheme(object pLogpal);
};
#endregion
}
Stop asking about my world domination plan. You'll find out when the time comes.
|
|
|
|
|