Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
NvrBst - 19 Dec 2007 20:14 GMT
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
bruce barker - 19 Dec 2007 20:49 GMT
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)

> Hello.  I posted this problem in the
> microsoft.public.dotnet.languages.csharp origionally but moving it
[quoted text clipped - 29 lines]
>
> NB
NvrBst - 20 Dec 2007 01:17 GMT
On Dec 19, 12:49 pm, bruce barker
<brucebar...@discussions.microsoft.com> wrote:
> OnPageStart is only called from HttpServerUtility.CreateObject, which is what
> you should use.
[quoted text clipped - 47 lines]
>
> - 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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.