page_load is ignored / asp.net 2.0

  • Thread starter Thread starter NorbertH
  • Start date Start date
N

NorbertH

Hi,

I am stucked in the following problem: I am using some Ajax
(javascript) code and I call via xmlhttprequest an aspx File. In the
code-behind aspx.vb file, I am creating an XML and want to send it
back.

Now, as soon as I remove all the html-tags (because I don't need it
for xml) in the aspx file (except the first line e.g. "<%@ Page
Language="VB" AutoEventWireup="true" CodeFile="some_main.aspx.vb"
Inherits="_some_main" %>") the page_load event will be ignored.

E.g. When I set the debugger breakpoint to the line "public writer as
xmlwriter = nothing" (see code below) and press f11 (next step) during
debugging, the program jumps to the next free line after "End Class",
and simply ignores the page_load.
------------------------------------------
Imports System.Web
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Net
Imports System.IO
Imports Microsoft.VisualBasic

Partial Class _some_main
Inherits System.Web.UI.Page

Public Writer As XmlWriter = Nothing

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
[.... and so on ...]
------------------------------------------

I've tried some coding with "AddHandler Page.Load, AddressOf
Page_Load" within the added function "Private Function
InitializeComponent()", but I didn't suceed.

Thanks for you help.

Best regards,

Norbert
 
Hi,
Hi,

I am stucked in the following problem: I am using some Ajax
(javascript) code and I call via xmlhttprequest an aspx File. In the
code-behind aspx.vb file, I am creating an XML and want to send it
back.

Now, as soon as I remove all the html-tags (because I don't need it
for xml) in the aspx file (except the first line e.g. "<%@ Page
Language="VB" AutoEventWireup="true" CodeFile="some_main.aspx.vb"
Inherits="_some_main" %>") the page_load event will be ignored.

I believe that you must at least have a FORM tag wth runat=server for
the page to be considered valid ASPX. If you remove everything including
the FORM tag, then I don't think that event wiring will work. I might be
wrong though (though your experience seems to prove me right).

If you don't need any HTML tags in your code, and you do every request
using AJAX, then you shouldn't use a Page anyway. Your website will be
much more efficient if you use an ASHX custom HTTP handler instead, for
example, because you will not fire all the events that a Page does, and
which you don't need anyway.

See any example of ASHX here:
http://www.galasoft-lb.ch/mydotnet/articles/article-2006100601.aspx

Greetings,
Laurent
 
Hi Laurent,

That was exactly what I was looking for! I did rewrite the code now,
this time by using an ashx file, and it's running perfect.
Thank you for your information and the link!

Greetings,
Norbert
 
Back
Top