Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Asp.Net Programming

How to set the @Page Async value without an .aspx file?

I have a class file in my App_Code folder called "clsBasePage.vb" that looks
like this:

Public Class clsBasePage
    Inherits System.Web.UI.Page
End Class

It's a "page" in that it inherits from ui.page, but has no .aspx file.  It's
just a class file.

In creating a new page for my website, say mynewpage.aspx, I remove the
IDE's automatic header & form html so all it contains is this:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="mynewpage.aspx.vb"
Inherits="mynewpage" %>

And I make mynewpage.aspx.vb inherit from clsBasePage, like this:

Partial Class mynewpage
    Inherits clsBasePage
End Class

I've recently added this method to clsBasePage

Public Sub GetTheTextFromTheOtherWebsite()

     Me.objWebClient = New System.Net.WebClient

     With objWebClient
          .Headers.Item(Net.HttpRequestHeader.Referer) = "localhost"
          .Headers.Item(Net.HttpRequestHeader.UserAgent) = "my web app v1.0"
          .BaseAddress = "https://www.theotherwebsite.com"
          .DownloadStringAsync(New System.Uri("cgi/server/textmaker.exe",
      End With

End Sub

When I call GetTheTextFromTheOtherWebsite from mynewpage, the
.DownloadStringAsync() method of the WebClient object is throwing this

"Asynchronous operations are not allowed in this context. Page starting an
asynchronous operation has to have the Async attribute set to true and an
asynchronous operation can only be started on a page prior to
PreRenderComplete event."

I believe the typical "fix" for this would be to add the Async="true"
attribute to the @Page directive so that the page can perform an Async task.
Adding this value to mynewpage doesn't change anything, I think I need to
add it to clsBasePage instead.  What's got me stumped here is that
clsBasePage doesn't have an .aspx file or a @Page directive at all, so I'm
not sure how to set that Async value to true on my base page class.

Have you tried adding the Async="true" attribute as instructed by the
exception message?

<%@ Page Language="VB" Async="true" AutoEventWireup="false"
Inherits="mynewpage" %>

Site:  http://www.eggheadcafe.com
UnBlog:  http://petesbloggerama.blogspot.com
Short urls & more:    http://ittyurl.net

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc