COMs OnPageStart() Not Firing when using ASP.NET/C#

N

NvrBst

Hello. I posted this problem in the
microsoft.public.dotnet.languages.csharp origionally but moving it
here since I think it probably belongs here now.

I have a blank ASP.NET/C# page with a code behind file. I made the
following function in the code behind file

public string GetFlower(){TEST.Flower myFlower = new TEST.Flower();
return myFlower.get_GetFlower(2);}

And in my form I do "<% Response.Write(GetFlower()); %>" But I get
null because varibles in the COMs "CFlower::OnPageStart(IUnknown*
piUnk) {...}" method isn't getting set. I have old ASP.NET/
JScript.NET pages that call the function like so "var myFlower =
Server.Create("TEST.Flower"); Response.Write(myFlower.GetFlower(2));"
and it works fine.

Does "new TEST.Flower();" not call "OnPageStart(...)" function
automatically like "Server.CreateObject("TEST.Flower");" does? The
TEST.dll is added to the ASP.NET/C# pages and intellisence sees all my
methods. Small Note: when I do "myFlower.GetFlower(2);" C# tells me
to use the direct accessor method "myFlower.get_GetFlower(2);". Could
this be why "OnPageStart(IUnknown* piUnk);" isn't being called?


I don't mind calling the "OnPageStart(IUnknown)" manually but I'm
unable to find what they want as the arg "IUnknown piUnk". My ASP.NET
Code behind file extends System.Web.Page so I think I should have the
"piUnk" they want someplace... I tried giving it a random number or
string but it just throws an exception.


Any help would be much apprisiated.


NB
 
B

bruce barker

OnPageStart is only called from HttpServerUtility.CreateObject, which is what
you should use.

if you want to call OnPageStart yourself, use:

[DllImport("webengine.dll")]
internal static extern int AspCompatOnPageStart(
[MarshalAs(UnmanagedType.Interface)] object comobj);

where obj is the com component.

if your component is apartment model (STA), then be sure the page is set as
AspCompat mode, or you will run into threading issues.


-- bruce (sqlwork.com)
 
N

NvrBst

OnPageStart is only called from HttpServerUtility.CreateObject, which is what
you should use.

if you want to call OnPageStart yourself, use:

[DllImport("webengine.dll")]
internal static extern int AspCompatOnPageStart(
[MarshalAs(UnmanagedType.Interface)] object comobj);

where obj is the com component.

if your component is apartment model (STA), then be sure the page is set as
AspCompat mode, or you will run into threading issues.

-- bruce (sqlwork.com)



NvrBst said:
Hello. I posted this problem in the
microsoft.public.dotnet.languages.csharp origionally but moving it
here since I think it probably belongs here now.
I have a blank ASP.NET/C# page with a code behind file. I made the
following function in the code behind file
public string GetFlower(){TEST.Flower myFlower = new TEST.Flower();
return myFlower.get_GetFlower(2);}
And in my form I do "<% Response.Write(GetFlower()); %>" But I get
null because varibles in the COMs "CFlower::OnPageStart(IUnknown*
piUnk) {...}" method isn't getting set. I have old ASP.NET/
JScript.NET pages that call the function like so "var myFlower =
Server.Create("TEST.Flower"); Response.Write(myFlower.GetFlower(2));"
and it works fine.
Does "new TEST.Flower();" not call "OnPageStart(...)" function
automatically like "Server.CreateObject("TEST.Flower");" does? The
TEST.dll is added to the ASP.NET/C# pages and intellisence sees all my
methods. Small Note: when I do "myFlower.GetFlower(2);" C# tells me
to use the direct accessor method "myFlower.get_GetFlower(2);". Could
this be why "OnPageStart(IUnknown* piUnk);" isn't being called?
I don't mind calling the "OnPageStart(IUnknown)" manually but I'm
unable to find what they want as the arg "IUnknown piUnk". My ASP.NET
Code behind file extends System.Web.Page so I think I should have the
"piUnk" they want someplace... I tried giving it a random number or
string but it just throws an exception.
Any help would be much apprisiated.
NB- Hide quoted text -

- Show quoted text -

Thanks for your very fast reply :) I still seem to have some
problems. I've tried the following

-----Inside the Code Behind File-----
public void GetFlower() {
//TEST.Flower myFlower = new TEST.Flower();
TEST.Flower myFlower =
(TEST.Flower)Server.CreateObject("TEST.Flower");
//TEST.Flower myFlower =
(TEST.Flower)Activator.CreateInstance(Type.GetTypeFromProgID("TEST.Flower"));
return myFlower.get_GetFlower(2);
}

-----Inside the Default.aspx-----
<% Response.Write(GetFlower()); %>


All 3 ways I assign "myFlower" seem to act identical. They call the
method in the COM I want, but the values set in the
"CTEST::OnPageStart(...) {...}" function are null. This is the
ASP.NET/C# pages. The old pages are ASP.NET/JScript.NET and when they
call Server.CreateObject it works fine (OnPageStart(...) values get
set); however, I do not wish to make new pages in JScript.NET since
Visual Studio doesn't support it, thus harder to create with the IDE.

I don't think I'm giving the right param to the
"AspCompatOnPageStart(...)" function you gave. I'm calling it like
so

-----Inside the Code Behind File (before the "return
myFlower.get_Get ...")-----
AspCompatOnPageStart(myFlower);
//AspCompatOnPageStart("TEST.Flower");
//AspCompatOnPageStart(Server.CreateObject("TEST.Flower"));
//AspCompatOnPageStart(myFlower.GetHash());
//myFlower.OnStartPage(...) //... = Top 4 repeated

The AspCompatOnPageStart always returns "1", and the
"myFlower.OnStartPage(Object piUnk)" returns void. None of them seem
to call the "CTEST::OnPageStart(...) {...}" method since it still
returns my "___ Object is Null" message.


If you have any throughts on some things I could try I'd be very
greatful. Right now I can just set the values I need in a
"if(value==null) *set value*" at the top of the Flower method and that
work s(since I'm only using 1 method at the moment in the C# pages).
However the COM has hundreds of methods and they all have the same
problem as above with the C# pages. The COM has to stay working with
the JScript.NET pages so I'd like to keep the OnPageStart method there
and have C# use that if its possible.

Thanks Again
NB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top