<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoadUserControl.aspx.cs" Inherits="LoadUserControl" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> </div> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoadUserControl.aspx.cs" Inherits="LoadUserControl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.IO; public partial class LoadUserControl : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [System.Web.Services.WebMethod] public static string UserControlLoader(string userControlName, string userControlParameter) { Page page = new Page(); LoadUserControlHelper userControl = (LoadUserControlHelper)page.LoadControl(userControlName); userControl.UserControlParameter = userControlParameter; userControl.EnableViewState = false; HtmlForm form = new HtmlForm(); form.Controls.Add(userControl); page.Controls.Add(form); StringWriter textWriter = new StringWriter(); HttpContext.Current.Server.Execute(page, textWriter, false); return textWriter.ToString(); } }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class LoadUserControl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
}
[System.Web.Services.WebMethod]
public static string UserControlLoader(string userControlName, string userControlParameter)
Page page = new Page();
LoadUserControlHelper userControl = (LoadUserControlHelper)page.LoadControl(userControlName);
userControl.UserControlParameter = userControlParameter;
userControl.EnableViewState = false;
HtmlForm form = new HtmlForm();
form.Controls.Add(userControl);
page.Controls.Add(form);
StringWriter textWriter = new StringWriter();
HttpContext.Current.Server.Execute(page, textWriter, false);
return textWriter.ToString();
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RSSReaderControl.ascx.cs" Inherits="RSSReaderControl" %> <asp:ListView runat="server" ID="PostList"> <LayoutTemplate> <ul> <asp:PlaceHolder runat="server" ID="itemPlaceholder" /> </ul> </LayoutTemplate> <ItemTemplate> <li><a href='<%# Eval("Link") %>'><%# Eval("Title") %></a> </li> </ItemTemplate> </asp:ListView>
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RSSReaderControl.ascx.cs" Inherits="RSSReaderControl" %>
<asp:ListView runat="server" ID="PostList">
<LayoutTemplate>
<ul>
<asp:PlaceHolder runat="server" ID="itemPlaceholder" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li><a href='<%# Eval("Link") %>'><%# Eval("Title") %></a>
</li>
</ItemTemplate>
</asp:ListView>
using System; using System.Linq; using System.Xml.Linq; public partial class RSSReaderControl : LoadUserControlHelper { protected void Page_Load(object sender, EventArgs e) { //UserControlParameter is defined in LoadUserControlHelper. //It is a string containing any parameter that is sent in using jQuery Ajax "data" option. XDocument feedXML = XDocument.Load(UserControlParameter); var feeds = from feed in feedXML.Descendants("item") select new { Title = feed.Element("title").Value, Link = feed.Element("link").Value, //Description = feed.Element("description").Value }; PostList.DataSource = feeds.ToList(); PostList.DataBind(); } }
using System.Xml.Linq;
public partial class RSSReaderControl : LoadUserControlHelper
//UserControlParameter is defined in LoadUserControlHelper.
//It is a string containing any parameter that is sent in using jQuery Ajax "data" option.
XDocument feedXML = XDocument.Load(UserControlParameter);
var feeds = from feed in feedXML.Descendants("item")
select new
Title = feed.Element("title").Value,
Link = feed.Element("link").Value,
//Description = feed.Element("description").Value
};
PostList.DataSource = feeds.ToList();
PostList.DataBind();
using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary> /// Summary description for LoadUserControlHelper /// </summary> public class LoadUserControlHelper : System.Web.UI.UserControl { public LoadUserControlHelper() { // // TODO: Add constructor logic here // } private string _userControlParameter; public string UserControlParameter { get { return _userControlParameter; } set { _userControlParameter = value; } } }
/// <summary>
/// Summary description for LoadUserControlHelper
/// </summary>
public class LoadUserControlHelper : System.Web.UI.UserControl
public LoadUserControlHelper()
//
// TODO: Add constructor logic here
private string _userControlParameter;
public string UserControlParameter
get { return _userControlParameter; }
set { _userControlParameter = value; }
<style type="text/css"> #RSSBlock { display: block; position: relative; float: left; border: 1px solid #666; width: 450px; height: 250px; overflow-y: auto; overflow-x: hidden; } #RSSContent { width: 100%; height: 100%; } #RSSBlock .loading { background: url('/images/progress-indicator.gif') no-repeat center; } #RSSBlock ul { list-style-type: none; line-height: 1.1em; font-size: 12px; margin: 0px; padding: 10px 10px 10px 10px; } #RSSBlock ul li { padding: 0px; margin: 0px; margin-bottom: 10px; } #RSSBlock a:link { } </style> <script type="text/javascript"> $(document).ready(function () { $.ajax({ type: "POST", url: "/LoadUserControl.aspx/UserControlLoader", data: MakeParameterList(["userControlName", "/RSSReaderControl.ascx", "userControlParameter", "http://www.luminowebdesign.com/rss"]), contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { $('#RSSContent').removeClass('loading'); $('#RSSContent').html(response.d); }, failure: function (msg) { $('#RSSContent').html(msg); } }); }); </script> <div id="RSSBlock"> <div class="loading" id="RSSContent"></div> </div>
function MakeParameterList(paramArray) { //-------------------------------------------------------------------------+ // Create list of parameters in the form: | // {"paramName1":"paramValue1","paramName2":"paramValue2"} | //-------------------------------------------------------------------------+ var paramList = ''; if (paramArray.length > 0) { for (var i = 0; i < paramArray.length; i += 2) { if (paramList.length > 0) paramList += ','; paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"'; } } paramList = "{" + paramList + "}"; return paramList; }
function MakeParameterList(paramArray) {
//-------------------------------------------------------------------------+
// Create list of parameters in the form: |
// {"paramName1":"paramValue1","paramName2":"paramValue2"} |
var paramList = '';
if (paramArray.length > 0) {
for (var i = 0; i < paramArray.length; i += 2) {
if (paramList.length > 0) paramList += ',';
paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"';
paramList = "{" + paramList + "}";
return paramList;
Here's a short little BLOGGER BIO to tell you a little bit about my background - and why I chose to get into programming and SEO.
I grew up in Norway, but went to school in the U.S. I have a degreen in computer science from Arizona State University. After graduating I moved back to Norway where I got a job working at Norwegian Data and later IBM. I went on to do a Masters of Management at BI in Oslo. After several years as a senior executive at IBM I decided to start my own company, Apropos Internet. In 2004 I started Virosafe Norway, a company that imports and distributes data security products, and now I am CEO of Lumino as well.
It's always been essential for me to stay up to date on the latest trends and developments in technology - not only to stay current as a programmer, but also to ensure my success as an entrpreneur. Lumino blog articles contain a variety of topics that have been useful for my own businesses - perhaps you will find them useful as well.