February 2006 - Posts
Well, bit old technique. But still usefull in an object oriented programming world. Just did a small sample today about the PreviousPage property in ASP.NET 2.0 to answer a question. So thought of putting it, coz it might help someone else. And i will put how we used to do it in ASP.NET 1.1.
what im trying to do here is to extend the existing page class just to add custom property called TitleName.
//Custom page class
public class MyPage : Page
{
string _titlename;
//You defined property
public string TitleName {
get {
return _titlename;
}
set {
_titlename = value;
}
}
}
and when you want create a page just inherit from the MyPage class and assign a value to the TitleName.
public partial class MyPageA : MyPage
{
protected void Page_Load(object sender, EventArgs e)
{
this.TitleName = "ludmal";
}
protected void Button1_Click(object sender, EventArgs e)
{
//just a button click which takes u to the relevnt page
Server.Transfer("Default.aspx");
}
}
So, using Server.Transfer("destination.aspx") will execute the current page and give the access to its property from the desination.aspx page.
To get the property value, in ASP.NET 1.1 we have to use the Context.Handler and cast it to the relevent page. But ASP.NET 2.0 already provided a property called PreviousPage where we can access the previous page instance.
ASP.NET 1.1protected void Page_Load(object sender, EventArgs e)
{
//Always we have to cast to the relevent page.
MyPage p = (MyPage)Context.Handler;
this.Label1.Text = p.TitleName;
}ASP.NET 2.0 protected void Page_Load(object sender, EventArgs e)
{
//cast and access the previous page property
// you can use it without casting if you directly refering to the previous page.
//In this scenario im using the extended page.. just to show the Extendibility MyPage p = (MyPage)Page.PreviousPage;
this.Label1.Text = p.TitleName;
}
Most of the developers out there already know what is a resource file.. so that I will refrain from explaining about resource files. Whole idea of this post is to show how to Get the Name,Values collection from the resource file and assign it to a custom collection.
So here is the code. Just let me know if you guys can find a better way of doing this.
public ReportItemCollection GetResource(){
CultureInfo c = CultureInfo.CurrentCulture;
ResourceManager m = new ResourceManager("ResourceFilesTest.ReportsMapping", Assembly.GetExecutingAssembly());
ResourceSet rset = m.GetResourceSet(c,true,true);
System.Collections.IDictionaryEnumerator idic = rset.GetEnumerator();
CustomCollection _coll = new CustomCollection();
Item item = null;
while(idic.MoveNext()){
item = new Item();
item.Name = (string)idic.Key;
item.Value = (string)idic.Value;
_coll.Add(item);
}
return CustomCollection;
}
While i was compiling a project with VS 2003, i got this error saying "Could not copy temporary files to the output directory, Files are used by another process". I was wondeing what was the problem, tryied iisreset but didnt work. Then i got to know that it was bug from VS. But the
Microsoft article couldnt solve the problem. Just did a workaround and it worked. Hope this will helpful to you guys also if you face the similar problem.
Select all the thirdparty DLL in the reference and set the
Copy Local = false.
VS Rocks!! Yeah it is.! The event was cool, well organized.
And some very good sessions also about techie stuff. Even though I couldn’t attend
to some of the session, I didn’t miss the party. It really rocks with Wildfire
and with lots of friends… always good see old friends… well done MS!!
While I was listing to the radio in the morning I heard about
CVS(Computer Vision Syndrome). If you’re a programmer, of course most of the
time your in front of the computer. So I think this might
be useful for you to get away from the
CVS.