[Mono-dev] System.Web.Extensions testing under mojoPortal
Joe Audette
joe.audette at gmail.com
Wed Aug 29 07:21:35 EDT 2007
Hi All,
Yesterday I managed to get UpdatePanel working in mojoPortal using
Mono from svn r84961 and mojoportal from svn trunk:
https://forgesvn1.novell.com/svn/mojoportal/trunk
I encountered a bug that needs to be fixed but was able to work around it.
The bug was a null reference on any controls inside the UpdatePanel
and the workaround was to get the needed reference using
UpdatePanel1.FindControl(...)
Relevant code from BlogEdit.aspx and BlogEdit.aspx.cs:
<asp:TextBox id="txtCategory" runat="server" Columns="50"></asp:TextBox>
<asp:Button id="btnAddCategory" runat="server"></asp:Button>
<div class="settingrow">
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional"
runat="server">
<ContentTemplate>
<asp:CheckBoxList id="chkCategories"
runat="server" SkinID="Blog"></asp:CheckBoxList>
</ContentTemplate>
</asp:UpdatePanel>
private void Page_Load(object sender, EventArgs e)
{
if (ScriptController != null)
{
ScriptController.RegisterAsyncPostBackControl(btnAddCategory);
}
else
{
log.Error("ScriptController was null");
}
if ((!Page.IsPostBack) && (!Page.IsCallback))
{
PopulateControls();
PopulateCategories();
}
}
private void PopulateCategories()
{
// Mono doesn't see this in update panel
// so help find it
if (chkCategories == null)
{
log.Error("chkCategories was null");
chkCategories =
(CheckBoxList)UpdatePanel1.FindControl("chkCategories");
}
if (ShowCategories)
{
chkCategories.Items.Clear();
IDataReader reader;
reader = Blog.GetCategoriesList(this.ModuleID);
while (reader.Read())
{
ListItem listItem = new ListItem();
listItem.Text = reader["Category"].ToString();
listItem.Value = reader["CategoryID"].ToString();
chkCategories.Items.Add(listItem);
}
reader.Close();
if (this.ItemID > -1)
{
reader = Blog.GetItemCategories(this.ItemID);
while (reader.Read())
{
ListItem item =
chkCategories.Items.FindByValue(reader["CategoryID"].ToString());
if (item != null)
{
item.Selected = true;
}
}
reader.Close();
}
}
}
protected void btnAddCategory_Click(object sender, EventArgs e)
{
if (this.txtCategory.Text.Length > 0)
{
int newCategoryID =
Blog.AddBlogCategory(this.ModuleID, this.txtCategory.Text);
if (this.ItemID > 0)
{
Blog.AddItemCategory(this.ItemID, newCategoryID);
}
PopulateCategories();
UpdatePanel1.Update();
}
}
With the workaround it does work on Mono. Even without the workaround
it worked on Windows using the Mono System.Web.Extensions.dll
When I tried to use the same dll on Mono 1.2.4 vm it did not work, it
compiled ok but at runtime I got an error about unkown type
System.Web.UI.Literal. I think the issue on 1.2.4 has to do with this
in Web.config:
<add tagPrefix="asp" namespace="System.Web.UI"
assembly="System.Web.Extensions"/>
Seems to lose track of all other controls in asp prefix that are not
in the System.Web.Extensions.dll. A workaround might be to use a
different prefix like ajax instead of asp.
I've been waiting a long time to be able to use UpdatePanel and other
MS Ajax stuff in mojoportal so I'm very happy to have progress but
would like to be able to use it more extensively without having to
.FindControl every control in the updatepanel
Thanks,
Joe
--
Joe Audette
Software Solutions Architect
Source Tree Solutions, LLC
joe.audette at gmail.com
http://www.sourcetreesolutions.com
http://www.mojoportal.com
More information about the Mono-devel-list
mailing list