RE: IE Hosted UserControl - javascript interaction not working.
- From: v-lliu@xxxxxxxxxxxxxxxxxxxx (Linda Liu [MSFT])
- Date: Mon, 18 Sep 2006 08:38:50 GMT
Hi Shaun,
To access public properties or invoke public methods of the control from
javascript in the web page, all we need to do is to build the control as a
COM class. To do this, right-click the project in the Solution Explorer and
choose Properties. In the Project Designer, select the Application tab and
click the 'Assembly Information' button on the right panel. In the Assembly
Information window, select the checkbox before the 'Make assembly
COM-Visible' option and press OK.
To expose events in the control to web pages and handle the events in the
web pages, we need to do more work. The following is the walkthrough.
1. Pack the events to be exposed into an interface, which is applied the
InterfaceTypeAttribute and then apply this interface to the control class.
The following is a sample.
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IMyControlCOMEvents
{
[DispId(0x60020000)]
void HostIdentificationComplete();
}
[ComSourceInterfaces(typeof(IMyControlCOMEvents))]
public partial class MyControl2 : UserControl
{
.........
}
2. Because we need to handle the event in the script in the web page, we
need assign the control assembly embeded in the web page the permission to
call unmanaged code. To do this, follow the steps below.
a. Type 'mscorcfg.msc' in the SDK command to open .Net Framework 2.0
Configuration.
b. In the configuration, navigate to My Computer->Runtime Security
Policy->Machine->Permission Sets. Right-click on the LocalIntranet sub
node and choose 'Duplicate'. A new permission set called 'Copy of
LocalIntranet' is generated.
c. Right-click on the new permission set and choose 'Change Permissions'.
In the Create Permission Set window, double-click the 'Security' item in
the right listbox. In the 'Permission Settings' window, select the checkbox
before the 'Allow calls to unmanaged assembly' option. Press OK and then
Finish button to close the windows.
d. Navigate to My Computer->Runtime Security Policy->Machine->Code
Groups. Right-click on the 'All_Code' node and choose 'New'. In the 'Create
Code Group' window, select the 'Create a new code group' option and type a
name for the new group and press Next. In the 'Choose the condition type
for this code group' combobox, select 'URL' and type the web site url into
the URL textbox, e.g. http://localhost/mytest/* and press Next. Choose 'Use
existing permission set' option and select 'Copy of LocalIntranet' in the
combobox and press Next. Press Finish.
3. Because the assembly that load the assembly of our control into the web
page doesn't have the permission to call the unmanaged code, we must assign
this permission to the assembly. To do this, we call the Assert method of
the Securitypermission class. The lines of code you wrote in the
DoHostIndenticationComplete method are correct.
Please follow the above steps to solve your problem and let me know the
result.
Sincerely,
Linda Liu
Microsoft Online Community Support
.
- Follow-Ups:
- References:
- IE Hosted UserControl - javascript interaction not working.
- From: sunev
- RE: IE Hosted UserControl - javascript interaction not working.
- From: Linda Liu [MSFT]
- IE Hosted UserControl - javascript interaction not working.
- Prev by Date: How to suppress new-data row in datagrid with parent-child data
- Next by Date: Re: Tooltip in TreeView control
- Previous by thread: RE: IE Hosted UserControl - javascript interaction not working.
- Next by thread: RE: IE Hosted UserControl - javascript interaction not working.
- Index(es):