Hi,
I've been building a mobile custom web control using MSDN and various
articles as a guide. The purpose of the control is to retrieve a
document at a url and display its contents. Right now, I would be happy
if I could get it to simply display a fixed string!
So, I created a control:
------------------------
using System;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Diagnostics;
namespace MicroSearch.MobileControls
{
public class DocViewer : MobileControl
{
private string url_ = "";
public String Url
{
get
{
Debug.WriteLine("get url: " + url_);
return url_;
}
set
{
url_ = value;
Debug.WriteLine("set url: " + url_);
}
}
}
}
and a control adapter for html devices:
---------------------------------------
using System;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
using System.Diagnostics;
namespace MicroSearch.MobileControls.Adapters
{
class HtmlDocViewerAdapter : HtmlControlAdapter
{
protected new DocViewer Control
{
get
{
Debug.WriteLine("new DocViewer");
return (DocViewer)base.Control;
}
}
public override void Render(HtmlMobileTextWriter writer)
{
Debug.WriteLine("Render");
writer.Write("I am here!");
}
}
}
the control and the adapter are built into an assembly: msmobile.dll
which is then referenced by the application:
-------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Search.aspx.cs"
Inherits="Search" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<%@ Register TagPrefix="msmobile" Namespace="MicroSearch.MobileControls"
Assembly="msmobile" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<mobile:Form ID="SearchForm" Runat="server">
<mobile:Label ID="Label" Runat="server"
Alignment="Center">Search</mobile:Label>
<mobile:TextBox ID="SearchText" Runat="server" Alignment="Center"
OnTextChanged="SearchText_TextChanged"></mobile:TextBox>
<mobile:Command ID="SearchCmd" Runat="server" Alignment="Center"
OnClick="SearchCmd_Click">Search</mobile:Command>
<mobile:Label ID="ErrorMsg" Runat="server" ForeColor="Red"
Alignment="Center" BackColor="White"></mobile:Label>
</mobile:Form>
<mobile:Form ID="ResultsForm" Runat="server">
<mobile:List ID="ResultList" Runat="server" DataTextField="Text"
DataValueField="Value"></mobile:List>
</mobile:Form>
<mobile:Form ID="ViewForm" Runat="server">
<mobile:Label ID="Title" Runat="server" BackColor="LightCyan"
ForeColor="Blue"></mobile:Label>
<msmobile

ocViewer ID="DocumentViewer" Runat="server"
Visible="True" />
</mobile:Form>
</body>
</html>
and finally I added a device adapter entry in the app's web.config file:
-------------------------------
<mobileControls sessionStateHistorySize="6"
cookielessDataDictionaryType="System.Web.Mobile.Co okielessData">
<device name="MicroSearchHtmlDeviceAdapters"
inheritsFrom="HtmlDeviceAdapters"
predicateClass="System.Web.UI.MobileControls.Adapt ers.HtmlPageAdapter"
predicateMethod="DeviceQualifies"
pageAdapter="System.Web.UI.MobileControls.Adapters .HtmlPageAdapter">
<control name="MicroSearch.MobileControls.DocViewer,msmobil e"
adapter="MicroSearch.MobileControls.Adapters.HtmlD ocViewerAdapter,msmobile"/>
</device>
</mobileControls>
Everything builds just fine, then I run it and get:
-----------------------------
Server Error in '/MobileWS' Application.
--------------------------------------------------------------------------------
MicroSearch.MobileControls.Adapters.HtmlDocViewerA dapter..ctor()
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.MethodAccessException:
MicroSearch.MobileControls.Adapters.HtmlDocViewerA dapter..ctor()
Source Error:
[No relevant source lines]
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary
ASP.NET Files\mobilews\baf280a3\14ea269b\App_Web_gn20izer. 0.cs Line: 0
Stack Trace:
[MethodAccessException:
MicroSearch.MobileControls.Adapters.HtmlDocViewerA dapter..ctor()]
T_6e0ac78c_f36d_4b8f_86bc_f9657d47809a.CreateInsta nce() +0
System.Web.UI.MobileControls.IndividualDeviceConfi g.NewControlAdapter(Type
originalControlType) +12
System.Web.UI.MobileControls.MobilePage.GetControl Adapter(MobileControl
control) +38
System.Web.UI.MobileControls.MobileControl.get_Ada pter() +38
System.Web.UI.MobileControls.MobileControl.OnUnloa d(EventArgs e) +22
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +267
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +204
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +204
System.Web.UI.Page.UnloadRecursive(Boolean dispose) +20
System.Web.UI.Page.ProcessRequestCleanup() +40
System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +213
System.Web.UI.Page.ProcessRequest() +86
System.Web.UI.Page.ProcessRequestWithNoAssert(Http Context context) +18
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.search_aspx.ProcessRequest(HttpContext context) in
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET
Files\mobilews\baf280a3\14ea269b\App_Web_gn20izer. 0.cs:0
System.Web.CallHandlerExecutionStep.System.Web.Htt pApplication.IExecutionStep.Execute()
+303
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +64
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.832;
ASP.NET Version:2.0.50727.832
Any ideas as to what's going on?
Thanks,
FGB