I'm quite new to Visual Studio. I'm working right now on Visual Studio Express 2013 and I'm trying to fill a certain textbox in ASP.net
I'll summarize everything as best as I can (I'm not a native english speaker)
First I had this problem with the invalid postback thing. I've found only one correct solution right here : https://johanleino.wordpress.com/2009/11/17/cascadingdropdown-causes-invalid-postback-or-callback-argument-error/
So, that's why I have NoValidationDropDownList instead of classical dropDownList
Also, I have 2 DropDownList using the ajax CascadingDropDown (I'm filling the second one depending on the selected value of the first one)
Here's my view :
<asp:TableCell>
<asp:NoValidationDropDownList OnSelectedIndexChanged="DropDownListVille_SelectedIndexChanged" ID="DropDownListVille" runat="server" class="ddlVille" ></asp:NoValidationDropDownList>
<ajax:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="Ville"
TargetControlID="DropDownListVille" PromptText="Non définie" LoadingText="Chargement des villes"
ServiceMethod="AfficherVille" ServicePath="CascadingDropDown.asmx"></ajax:CascadingDropDown>
</asp:TableCell>
<asp:TableCell runat="server">
<asp:NoValidationDropDownList ID="DropDownListRue" runat="server" class="ddlRue" OnSelectedIndexChanged="DropDownListVille_SelectedIndexChanged"></asp:NoValidationDropDownList>
<ajax:CascadingDropDown ID="ccdRegion" runat="server" Category="Rue" ParentControlID="DropDownListVille"
TargetControlID="DropDownListRue" PromptText="Non définie" LoadingText="Chargement des rues"
ServiceMethod="VilleRueLier" ServicePath="CascadingDropDown.asmx"></ajax:CascadingDropDown>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="TextBoxCP" runat="server" class="tbcp"></asp:TextBox>
</asp:TableCell>
My first dropdown have cities, second one have streets and my textbox have postcode. All data is coming from one DB using these two tables :
Ville(Id_Ville, nom_ville, code_postal)
Translated in
city(id_city,city_name,postcode)
Rue(Id_Rue,Nom_Rue)
Translated in
street(id_street,street_name)
I would like to dynamically change the postcode depending on the id of the selected city (This id is stored as a value in the dropdownlist).
See, when the city the user want is not in the db, he can select a special value of the first dropdownbox, and add a new city.
When he does that, the page display some textbox with ajax.
There, the user can add a new city with its postcode. Else, the postcode TextBox is on readonly.
But when he choose a listed city, I want the textbox to fill itself.
There's my webservice methods, linked to the cascadingDropDown :
[System.Web.Script.Services.ScriptService()]
public class WebService1 : System.Web.Services.WebService
{
private Passerelle.Passerelle passerelle = new Passerelle.Passerelle();
[WebMethod]
public CascadingDropDownNameValue[] AfficherVille(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> VilleDetails = new List<CascadingDropDownNameValue>();
ListVille listeVille = new ListVille();
listeVille = passerelle.getListVille();
foreach (Ville v in listeVille.List)
{
string idVille = v.IdVille.ToString();
string nomVille = v.NomVille.ToString();
VilleDetails.Add(new CascadingDropDownNameValue(nomVille, idVille));
Debug.WriteLine("Id Ville = " + idVille + " ----- NomVille = " + nomVille);
}
return VilleDetails.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] VilleRueLier(string knownCategoryValues, string category)
{
///GET DATA FROM SQL
ListRue listeRue = new ListRue();
StringDictionary VilleDetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int idVille = Convert.ToInt32(VilleDetails["Ville"]);
List<CascadingDropDownNameValue> countrydetails = new List<CascadingDropDownNameValue>();
//Here I get the data from my table 'Rue' with the ID coming from
listeRue = passerelle.getListRue(idVille);
countrydetails.Add(new CascadingDropDownNameValue("Pas dans la liste", "-1"));
foreach (Rue r in listeRue.list)
{
string idRue = r.idRue.ToString();
string nomRue = r.nomRue.ToString();
countrydetails.Add(new CascadingDropDownNameValue(nomRue, idRue));
Debug.WriteLine("Id rue = " + idRue + " ----- NomRue = " + nomRue);
}
return countrydetails.ToArray();
}
}
I've Tried many things... Classic events to some ajax function calls.
And I just can't figure out how to do that ...
And of course I'm following classic MVC pattern. So... No sql request in the view.
I'm not doing great with ajax.
I'm probably missing some great ajax/asp.net feature with another webMethod.
Many thanks to anyone who can help me.
And sorry for all the spelling/grammar mistakes.
I won't be able to answer for some hours (I'll come back in something like ~12 hours) If you have any questions ... I'll be there to answer you.
Ok my bad.
My event were not working because I forgot the AutoPostBack=true.
Using UpdatePanel all around my view's items to deny refreshing the page, I've now fixed everything.
Related
I'm opening a new window to another .aspx page in which I pass a couple of parameters and I wanted to re-pass the parameter ID from the actual page:
<asp:Button ID="Button1" runat="server" CausesValidation="False" meta:resourceKey="btnAddRow2"
OnClientClick="window.open('SecondPage.aspx?type=Usuaris&id=SPECIALID', '_blank')" Text="Miau" />
As you can see, the type parameter works well but I don't have the slightest idea how to get the "specialID" from the current page which would be:
http://blablabla.com/FirstPage.aspx?SPECIALID=36
So i want to get that 36 (which is a dynamic number so I can't actually put a 36 directly over there) in order to open the second page as follows:
http://blablabla.com/SecondPage.aspx?type=Usuaris&SPECIALID=36
As I said at the beginning the user IS at he FirstPage.aspx and upon pressing a button will go to the SecondPage.aspx
hi you can change the OnClientClick to call a javascript function which will get the specialId and then call the window.open with the full string.
for example
function openWindow(){
var specialId = document.getElementById('someElement').value;
window.open('SecondPage.aspx?type=Usuaris&id=' + specialId, '_blank')"
}
I finally could do it doing the following in the FirstPage.aspx:
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
function AddUsuario() {
var id = getParameterByName("id");
window.open('SecondPage.aspx?type=Usuarios&id=' + id, '_blank');
location.reload();
}
On Page_Load() do following
Button1.Attributes.Add("onclick",
String.Format("window.open('SecondPage.aspx?type=Usuaris&id={0}', '_blank');",
Request.QueryString["SPECIALID"]));
I have created a property under a MemberType called "testField" which is using a custom DataType dropdown list with 2 values in it (Employee and Subcontractor). I would like for a member to be able to select one, submit a form and to store their selection under this property, but I can't seem to figure it out.
Is it possible to do this whilst being able to change their selection manually in the back end?
Here's my code...
ASCX
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Register.ascx.cs" Inherits="nForum.usercontrols.nForum.membership.Register" %>
<div id="forumregistration" class="validate">
<dl class="form">
<dt><label for="<%= tbLoginName.ClientID %>">Login/Username:</label></dt>
<dd><asp:TextBox ToolTip="Enter username" CssClass="required" ID="tbLoginName" runat="server" /></dd>
<dt><label for="<%= tbName.ClientID %>">Full Name:</label></dt>
<dd><asp:TextBox ToolTip="Enter name" CssClass="required" ID="tbName" runat="server" /></dd>
<dt><label for="<%= tbEmail.ClientID %>">Email:</label></dt>
<dd><asp:TextBox ToolTip="Enter email address" CssClass="required email" ID="tbEmail" runat="server" /></dd>
<dt><label for="<%= tbPassword.ClientID %>">Password:</label></dt>
<dd><asp:TextBox ToolTip="Enter a password" CssClass="required password" ID="tbPassword" TextMode="Password" runat="server" /></dd>
<dt><label for="">Status:</label></dt>
<asp:dropdownlist ID="tbOrganisation" runat="server">
<asp:ListItem Text="Choose" Value="0"></asp:ListItem>
<asp:ListItem Text="Employee" Value="1"></asp:ListItem>
<asp:ListItem Text="Subcontractor" Value="2"></asp:ListItem>
</asp:dropdownlist>
<dt> </dt>
<dd><asp:Button ID="btnSubmit" CssClass="textarea" runat="server" Text="Create Account" onclick="BtnSubmitClick" /></dd>
</dl>
</div>
CS
using System;
using System.Text;
using System.Web.Security;
using nForum.BusinessLogic;
using umbraco;
using umbraco.cms.businesslogic.member;
namespace nForum.usercontrols.nForum.membership
{
public partial class Register : BaseForumUsercontrol
{
protected void BtnSubmitClick(object sender, EventArgs e)
{
var redirecturl = Settings.Url;
// Check the user isn't already registered
if (Member.GetMemberFromEmail(Helpers.GetSafeHtml(tbEmail.Text)) == null & Member.GetMemberFromLoginName(Helpers.GetSafeHtml(tbLoginName.Text)) == null)
{
// Set the member type and group
var mt = MemberType.GetByAlias(MembershipHelper.ForumUserRoleName);
var addToMemberGroup = MemberGroup.GetByName(MembershipHelper.ForumUserRoleName);
//create a member
var m = Member.MakeNew(Helpers.GetSafeHtml(tbName.Text), mt, new umbraco.BusinessLogic.User(0));
//var mstatus = new MembershipCreateStatus();
//var mp = Membership.CreateUser(tbName.Text, tbPassword.Text, tbEmail.Text, string.Empty, string.Empty, true, out mstatus);
// Set the other properties
m.Email = Helpers.GetSafeHtml(tbEmail.Text);
m.LoginName = Helpers.GetSafeHtml(tbLoginName.Text);
m.Password = Helpers.GetSafeHtml(tbPassword.Text);
// Add 0 Karma to user, helps us later in the site
m.getProperty("forumUserKarma").Value = 0;
m.getProperty("forumUserAllowPrivateMessages").Value = 1;
m.getProperty("forumUserLastPrivateMessage").Value = DateTime.Now;
// Take selected dropdown value and store
m.getProperty("testField").Value = tbOrganisation;
//##### Manual Member Authorisation #####
// If this is not enabled, mark the member as authorised
if (!Settings.ManuallyAuthoriseNewMembers)
{
m.getProperty("forumUserIsAuthorised").Value = 1;
}
m.AddGroup(addToMemberGroup.Id);
//Save member
m.Save();
//Generate member Xml Cache
m.XmlGenerate(new System.Xml.XmlDocument());
if (!Settings.ManuallyAuthoriseNewMembers)
{
//Login the user so they can be redirected to their profile page
FormsAuthentication.SetAuthCookie(tbLoginName.Text, false);
}
else
{
redirecturl = string.Concat(CurrentPageAbsoluteUrl, "?m=", library.GetDictionaryItem("NotifiedWhenAccountAuth"));
}
// If admins wants email notification, then send it here
if (Settings.EmailAdminOnNewMemberSignUp)
{
SendAdminNotification(m);
}
}
else
{
redirecturl = string.Concat(CurrentPageAbsoluteUrl, "?m=", library.GetDictionaryItem("UserAlreadyExists"));
}
// Now redirect to the correct page
Response.Redirect("/discuss-it");
}
private void SendAdminNotification(Member newmember)
{
var sb = new StringBuilder();
sb.AppendFormat(library.GetDictionaryItem("MemberSignUpEmailText"),
Settings.Name,
newmember.LoginName,
newmember.Text,
newmember.Email);
Helpers.SendMail(Settings.EmailNotification, Settings.EmailAdmin, library.GetDictionaryItem("NewMemberSignUp"), sb.ToString());
}
}
}
Your specific issue is two fold:
1) You are setting m.getProperty("testField") to the instance of the DropDownList
rather than to it's SelectedValue
2) As noted in the comments on the question you had a mis-match in your hardcoded DropDownList values
and the values stored in the Umbraco DataType for the testField property.
You can address the second issue more robustly by binding your DropDownList with what Umbraco calls
the PreValues stored on the testField DataType is will ensure the available options in the DropDownList
match the options defined on the DataType
As of writing this PreValues are stored as an XML fragment on the datatype definition in
the following format:
<preValues>
<preValue id="1">Option 1</preValue>
<preValue id="2">Option 2</preValue>
<preValue id="3">Option 3</preValue>
</preValues>
To retrieve these programmatically is a little clunky (IMO); You first you have to obtain the Id of DataType by
mousing over the DataType in the umbraco interface and looking in the status bar (you should see something like javascript:openDataType(1111) where 1111 is the Id.
Next call the umbraco.library.GetPreValues() method, passing in the Id obtained above. This method
returns an XPathNodeIterator which you can use to get the values in whichever way suits your need such as creation of a Dictionary<string,string> which you can bind to your DropDownList. The following example is taken from Damiaan Peeters blog
and adapted ever so slightly.
private static Dictionary<string, string> GetPreValues(int dataTypeId)
{
XPathNodeIterator preValueRootElementIterator = umbraco.library.GetPreValues(dataTypeId);
preValueRootElementIterator.MoveNext(); //move to first
XPathNodeIterator preValueIterator = preValueRootElementIterator.Current.SelectChildren("preValue", "");
var retVal = new Dictionary<int, object>();
while (preValueIterator.MoveNext())
retVal.Add(preValueIterator.Current.GetAttribute("id", ""), preValueIterator.Current.Value);
return retVal;
}
Then in your code behind you can do the following:
tbOrganisation.DataSource = GetPreValues(1111);
tbOrganisation.DataTextField = "Value";
tbOrganisation.DataValueField = "Key";
tbOrganisation.DataBind();
private const int ItemsPerRequest = 10;
[WebMethod]
public RadComboBoxItemData[] GetAccount(object context)
{
RadComboBoxContext obj = (RadComboBoxContext)context;
DataTable data = GetDataAccount(obj.Text);
RadComboBoxData comboData = new RadComboBoxData();
int itemOffset = obj.NumberOfItems;
int endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count);
comboData.EndOfItems = endOffset == data.Rows.Count;
List result = new List(endOffset - itemOffset);
for (int i = itemOffset; i < endOffset; i++)
{
RadComboBoxItemData itemData = new RadComboBoxItemData();
itemData.Value = data.Rows[i]["AccountLevelNo"].ToString();
itemData.Text = data.Rows[i]["AccountDesc3"].ToString();
itemData.Attributes.Add("Level6", data.Rows[i]["AccountDesc2"].ToString());
itemData.Attributes.Add("Level1", data.Rows[i]["AccountDesc1"].ToString());
result.Add(itemData);
}
comboData.Items = result.ToArray();
// comboData.Message = GetStatusMessage(endOffset, data.Rows.Count);
return comboData.Items.ToArray();
}
private static DataTable GetDataAccount(string text)
{
int accCode = 0;
string query = "select COA.LevelAccountNo,COA.AccountDesc as AccountDesc3,Level1.AccountDesc as AccountDesc1, Level2.AccountDesc as AccountDesc2 from COA COA,(select LevelAccountNo,AccountDesc " +
"from COA where len(LevelAccountNo)=2)as Level1,(select LevelAccountNo,AccountDesc from COA where len(LevelAccountNo)=5)as Level2 " +
"where Level1.LevelAccountNo=left(COA.LevelAccountNo,2)and Level2.LevelAccountNo=left(COA.LevelAccountNo,5) and len(COA.LevelAccountNo)>6";
try
{
accCode = Convert.ToInt32(text);
query = query + " COA.LevelAccountNo like '" + text + "%'";
}
catch (Exception ex)
{
query = query + " COA.AccountDesc3 like '%" + text + "%'";
}
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"].ToString());
// string constr=ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlDataAdapter adapter = new SqlDataAdapter(query, con);
// adapter.SelectCommand.Parameters.AddWithValue("#text", text);
DataTable data = new DataTable();
adapter.Fill(data);
con.Close();
return data;
}
this is my web service code
Collapse | Copy Code
<telerik:RadComboBox ID="cboAccount" runat="server" Height="200" Width="200" EmptyMessage="Select an Account"
EnableLoadOnDemand="true" ShowMoreResultsBox="true" EnableVirtualScrolling="true">
<HeaderTemplate>
<h3>Accounts</h3>
</HeaderTemplate>
<ClientItemTemplate>
<div>
<ul>
<li><span><b>Name:#= Text # </b></span></li>
<li><span>Level6 #= Attributes.Level6 # </span></li>
<li><span>Level1: #= Attributes.Level4 # </span></li>
<li><span>Level4 #= Attributes.Level1 # </span></li>
</ul>
</div>
<br></br>
</ClientItemTemplate>
<WebServiceSettings Method="GetAccount" Path="InvestmentDropDownWebService.asmx" />
</telerik:RadComboBox>
I am using for the first time webservice in my project. I don't know how to solve this error. If I am running aspx.cs this is perfectly running and values bind in combo box. But when I am binding values to combobox by using web service, its gives an error:
The type Telerik.Web.UI.RadComboBoxContext is not supported because it implements IDictionary.
This issue arise because of Visual Studio debugger. It's because of it's default behaviour. There's a workaround for that. Change your line
[WebMethod]
to
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
And also, Add an attribute of
WebServiceSettings-UseHttpGet="true"
in your ASPX code of RadCombo Box.
See this question in Telerik forum for more details regarding this issue
The cause of the problem is (xml)serialization.
Remember, the serialization-mechanism was built at the very start of the platform, nice things as generic-collections/dictionaries were added after.
This means that functionality that you would expect to work now, may not have been possible during the initial development.
Which brings us to the dictionary.
The base class of the dictionary does not support serialization, because the serializer does not like/handle 'unknown' types very much. Since dictionaries could be '[object, object]', it is unknown-type heaven.
An interesting way to create a similar unknown type problem is as follows.
Create a webservice that expects class 'a' as a parameter.
Create a web-reference to the service.
Create class 'b' that derives from 'a'.
Now call the webmethod with an instance of 'b' as a parameter
You will now get an error message saying that the call failed because 'type b was unexpected'. I hope you can see how these two things (unexpected type/dictionary) are related...
You can only give an xml serializer the types it was told to expect at design-time
The solution of 'sohaiby' will work because he is telling the webservice NOT to use xml-serialization, but to use JSON in the line:
ResponseFormat = ResponseFormat.Json
This all being said, this is really Telerics fault and they should fix it.
I need to keep using a list box to do this as there are a number of other dependencies on the control being a list box.
Ultimately I want each list item to consist of 3 distinct URL's so:
Url1 Url2 Url3
which would be HTML of:
<ul>
<li>Url1Url2Url3</li>
</ul>
So in my ASPX page I am maintaing there is already:
<asp:BulletedList ID="lstDashboards" runat="server" DisplayMode="Text"</asp:BulletedList>
And in code behind I have the following to populate the list:
private void GuiSideMenuBuild(Int64 aUserId)
{
//Always clear any dashboards
lstDashboards.Items.Clear();
//Get the dashboards from the database
DashboardsForUserGetDto userDashboards = DashboardBL.Instance.DashboardsForUserGet(Convert.ToInt32(aUserId));
const string HREF_DASHBOARD_EDIT = "Edit...";
const string HREF_DASHBOARD_DELETE = "Delete...";
foreach (TableDashboardDashboardDtoBase userDashboard in userDashboards.Dashboards)
{
string listItemText = userDashboard.Title;
if (userDashboard.DashboardId == DashboardId)
listItemText += HREF_DASHBOARD_EDIT + HREF_DASHBOARD_DELETE;
ListItem listItem = new ListItem
{
Text = listItemText,
Value = Convert.ToString(userDashboard.DashboardId),
Selected = userDashboard.DashboardId == DashboardId
};
lstDashboards.Items.Add(listItem);
}
}
However the HTML that the control is producing has escaped all the supplied HTML so that I end up with something like:
<<a href="#" id="...
which means that the resulting HTML is "broken" and the URL's don't work. So my question is:
How can I keep using the existing list box (ie. asp:BulletedList) but supply it Text for the item so that it will produce valid HTML so that I can have 3 separate URL's?
I have already tried HTML Encoding the string before adding it to listItem.Text but that makes no difference.
I don't see any need for a UserControl here - you don't use any server-side components, you're just generating markup. Why not just do this in your .aspx page?
<ul>
<% foreach (TableDashboardDashboardDtoBase userDashboard in userDashboards.Dashboards)
{
%>
<li>Url1Url2Url3</li>
<%
}
%>
</ul>
Either that, or use a repeater:
HTML
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<ItemTemplate><li>Url1Url2Url3</li></ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
Code Behind
Repeater1.DataSource = userDashboards.Dashboards
Repeater1.DataBind()
Here's the deal. Have a functioning web app using ASP.NET WebForms with a C# backend. The thing works fine, but I'm always looking to improve, as a beginner at this stuff. Right now, to deal with a user's search coming back with no results, I utilize the following, and was wondering if there was any cleaner way to do it, for future reference:
DataClass data = new DataClass();
var searchresults = data.GetData(searchBox.Text);
int datanumber = searchresults.Count();
if (datanumber == 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "javascript:alert('There were no records found to match your search');", true);
}
else
{
DropDownList1.Visible = true;
DropDownList1.Items.Clear();
DropDownList1.DataSource = searchresults;
DropDownList1.DataBind();
}
I agree with the not using popups, so you could always do something as simple as having a Label object on your page:
<asp:Label runat="server" id="lblResultMsg" ForeColor="Red" Visible="False" />
And then set the text dynamically (or add it as a property to the code) and set the label to be visible on postback if no results are found:
if (datanumber == 0)
{
lblResultMsg.Text = "There were no records found to match your search.";
lblResultMsg.Visible = true;
}
else
{
lblResultMsg.Text = "";
lblResultMsg.Visible = false;
// do your data binding
}
But there are quite a vast number of ways you could achieve something like this. Regarding your question about using the .Count from the Enumerable collection - there's nothing stopping you doing this as it's perfectly valid. The question is which method do you find more readable?
if you include the jquery ui dialog (http://jqueryui.com/demos/dialog/), you can simply call this to create a nice dialog box:
$('<div>message</div>').dialog({autoOpen:true,title:'Error'});
Personally I prefer to create a helper function for inserting the relevant javascript into the page, and only pass parameters to the function so that I don't need to worry about the messy details every time.
Something like :
public static void GrowlMessage(System.Web.UI.Control pageControl, string header = "", string message = "", bool sticky = false, string position = "top-right", string theme = "", bool closer = true, int life = 8)
{
string _js = "$.jGrowl('" + HttpContext.Current.Server.HtmlEncode(message) + "', { header:'" + header + "', sticky:" + sticky.ToString().ToLower() + ", position: '" + position + "', theme: '" + theme + "', closer: " + closer.ToString().ToLower() + ", life:" + life * 1000 + "});";
ScriptManager.RegisterStartupScript(pageControl, pageControl.GetType(),"Growl",_js, true);
}
The sample I have used also requires jQuery and the jGrowl library available here. And IMHO the messages are pretty. They are unobtrusive, the user does not need to click a button to make them go away, and they fade away after your specified amount of time.
But I agree with Mike, that if you don't have any records, you should just use the built in properties of a GridView (EmptyDataRowStyle and EmptyDataRowText) to display a 'no data matching your query' style message. Assuming that you're using a GridView at all, that is..
When it comes to user feedback, Impromptu is my friend. There is a nice ASP.NET implementation of Impromptu on Aaron Goldenthal's website: http://www.aarongoldenthal.com/post/2009/11/11/Using-jQuery-Impromptu-With-ASPNET.aspx
If you have decided to alert user via alert then please go ahead with light box effect..
http://www.designyourway.net/blog/resources/30-efficient-jquery-lightbox-plugins/
if you are still would like to go ahead with traditional alert then obviously its easy for you to fire it up on page load rather than attaching script to it..
')" ....>
Because if you require any change then you just need to alter the javascript alone and you dont need to build project again to test it...
Hope its useful for you..
Note: I'm using my own DLLs to render content so above coding may requires alteration because i did forget traditional asp codings.. :)