Access Web Form member from it’s hosted windows user control

Hi.

I have a web app that uses a IE hosted windows user control. I would like that, somehow, lounch an external event from that hosted control that I could catch in my web form’s code behind or set a web form’s member value.

Does anybody know how to do that

I would appreciate any suggestions!

Thanks in advance!




Answer this question

Access Web Form member from it’s hosted windows user control

  • Mossa TheGreat

    I am getting the same thing.

    Plus one other interesting feature.

    I modified the control to add code to the cmdFireEvent_Click routine to show in the label whether the EventFired event variable was null.

    When I call up the display and click on the button the label says "null". It stays that way until I click somewhere off the control. Then when I click on the button the label says "not null", the code tries to raise the event and the security permissions error comes out.

    I have set the security on the control to Full Trust using .NET Configuration/Runtime Security Policy/Increase Assembly Trust/Make changes to this computer. That doesn't seem right as I want the policy on the control to apply to any computer I load it to but that is all I can find.

    Any idea


  • Cyber Wombat

    Strange is that I've developed this control with Framework 1.1, but I had to add full trust in the .NET Framework 2.0 Configuration tool for it to work (I have VS 2003 and 2005 both installed on my computer).

    I guess the solution is that on each machine the web site should be added to Trusted Sites and configure Full Trust for this category....That's how it worked for me.

    But I guess that's pretty much enough for me, cause I'm using this for my thesis to graduate university...It's not a commercial app.I just needed it to work somehow. That would do it for me.

    Thanks a million guys!



  • ProfEclipse

    Here is the answer to your problem...

    When you double click on the solution or the project Windows is trying to open the file using VS.Net 2003

    So... right click on the properties of the vs.net solution or project and go to the OPEN WITH, and choose the file type "Microsoft Visual Studio Version Selector" and tick the "Always use the selected program..."

    Windows will now open the project or solution with the correct version of VS.Net

    Took me ages to figure this out!!! Hope it helps

    Cheers
    Graeme


  • Labrego

    For all of you who are having problems with iexplore.exe.config, the project ZIP contains this file. It needs to be placed in your web root (i.e. "C:\InetPub\wwwroot"). It isn't neccesary for the project itself, just comment out the AppSettingsReader lines and you won't need it. I put it there to demonstrate how you can give app.config style config settings to your hosted control. Neat thing is that because it goes in the web root, you don't have to deploy config files to each machine.

    For those of you having problems with the project file, yes I built it in VS2005, but the project file has no important settings, so just add everything except the iexplore.exe.config and the html file to your project and it should work on all other editions of VS.

    The permission errors are caused by the fact that .NET sees the managed assembly as accessing unmanaged code (which it is: IE), and as such the assembly needs to have permissions to do this. The easiest way is to create a code group with a membership of URL, and put in for example http://localhost/IEEvents/*, then give it FullTrust. This permission must be set on the client. However, if you're in an enterprise, you could use the Enterprise policy to deploy the policy out. God knows how you do this though, I've never used it



  • Streers

    Actually, I've managed to open that project with VS 2003...is more like I've rebuild the project (build another one with the same name for the project and for the control and copy/paste the content of his files into your new ones) with the files that Sean provided in his project...

    But Sean, it still doesn't work. I don't get that code managed error ("No setting for button found in iexplore.exe.config!") anymore, but when I press the raise event button, I get this security policy error:

    Application attempted to perform an operation not allowed by the security policy. To grant this aplication the required permission, contact your system administrato, or use Microsoft .NET Framework Configuration tool.

    If you click continue, the application will ignore this error and attempt to continue.

    Request for the permission of type

    'System.Security.Permissions.SecurityPermission, mscorlib,

    Version=2.0.0.0, Culture=neutral,

    PublicKeyToken=b77a5c561934e089' failed.

    Details

    Version=2.0.0.0 is also suspitious....cause I was using Framework 1.1 (VS 2003). Do you have any ideea about this Sean



  • symbol123

    I've posted quite a long blog entry on this topic at http://dotnet.org.za/codingsanity/archive/2006/04/20/51710.aspx. I've also uploaded a sample project which you can access from http://www.codingsanity.com/winieevents.htm. I'd suggest you read the blog entry first, since there's quite a few things to look out for, and a couple of nifty extras (like how to have an app.config type thing for your hosted controls).



  • Brian_InVa

    Thanks Sean! But still it isn't working....I get this message on the control:

    "No setting for button found in iexplore.exe.config!"

    followed by a security policy error after I push the Fire Event button from the hosted control.



  • dallanadia

    OK. It looks like I can easily copy the pieces into a VS 2003 project.
  • JockeOlsson

    First off you need to define your interface. This is a simple interface declaring the events you will fire, and any properties/methods you will access from the web page. It needs to be visible to COM, so use the following as a template:

    [GuidAttribute("1F98211C-7A71-4588-8D4A-AD85CA80BAE7"),
    InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
    public interface IMyEvents
    {
    // Add DisIdAttribute to any members in the source interface to specify
    //the COM DISPID.
    [DispIdAttribute(1)]
    void EventOne(object sender, System.EventArgs e);
    [DispIdAttribute(2)]
    void EventTwo(object sender, System.EventArgs e);
    [DispIdAttribute(3)]
    string Property();
    }

    Implement this interface on your .NET control, without inheriting the interface itself, and declare the ComSourceInterface for the control to be the interface defined above:

    // Add a ComSourceInterfaces attribute to the control to identify the list
    // of interfaces that are exposed as COM event sources.
    [ComSourceInterfaces("CL.Capture.IHostedFormEvents")]
    public class MyControl
    {

    public event EventHandler EventOne;
    public event EventHandler EventTwo;
    public string Property { get { return _prop; } set { _prop = value; } }
    }

    Now, in your HTML page, put the following:

    <OBJECT id="MyControl" height="100%" width="100%" classid="MyDll.dll#MyNamespace.MyControl"
    VIEWASTEXT>
    <PARAM NAME="Property" VALUE="ABC">
    </OBJECT>
    <script language="javascript" for="MyControl" event="EventOne()">
    <!-- Do stuff here -->
    </script>
    <script language="javascript" for="CaptureControl" event="EventTwo()">
    <!-- Do stuff here -->
    </script>



  • ChuckBuc

    I can't make it work. It seems that I'm missing somethimg. Can you please send me a small sample project (Hello World) on using that code at bozesan_mihai82@yahoo.com
    Thanks!


  • r4nd0m

    I had that problem too when I tried to open it with VS 2003. But it works with Visual Studio 2005. I quess that's a Visual Studio 2005 project.

  • Brian Cost

    Can you please tell me how can I fire that event from my control


  • gazzerh

    I am actively watching this form as well.

    My question is regarding the csproj file in the example. When I try to open it in Visual Studio 2003 I get the error "The project file is missing the 'VisualStudioProject' section."


  • Gohan

    I have another question:

    The web page http://support.microsoft.com/default.aspx scid=kb;EN-US;313891 talks about this topic and contains the statement:"On any client system, use the .NET Framework Configuration tool (Mscorcfg.msc) to grant the assembly the individual permissions that are required."

    This implies that the control must be preinstalled on the client system so that you can grant it permissions. That makes sense because a "Full Trust" control that came down from the web would be way too dangerous.

    Question is: If the control is to generate .COM events to IE does it have to be granted it's permissions explicitly on each client. I.e. by putting it into the GAC and then using Mscorcfg. Is there any way around this I want a control that can generate .COM events (and nothing else) but whose privileges come down with it automatically.


  • Access Web Form member from it’s hosted windows user control