467,925 Members | 2,017 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,925 developers. It's quick & easy.

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

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
Dec 19 '07 #1
  • viewed: 1530
Share:
2 Replies
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" wrote:
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
Dec 19 '07 #2
On Dec 19, 12:49 pm, bruce barker
<brucebar...@discussions.microsoft.comwrote:
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" wrote:
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.GetType FromProgID("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.Flo wer"));
//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
Dec 20 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by qaz | last post: by
3 posts views Thread by Mike | last post: by
5 posts views Thread by Raghu Raman | last post: by
19 posts views Thread by furiousmojo | last post: by
6 posts views Thread by Kevin Attard | last post: by
2 posts views Thread by Sam | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.