The old mate decided to move on, I firstly found
this but a bit afterward found the Telerik one,
JustDecompile . However, the output I got from the old mate (
http://www.reflector.net/) for extraxting code, on a same DLL was different. Redgate one's out put compiled straight away with much better solution structure output, indeed better.
These days people would expect a web page with absolute no post back rather than asking for it. Utilising Microsoft update panel is good but it is not always helpful. I recently come across a page and tried to do a quick fix using update panel. The result was randomly throwing error...
The best practice would be using JQuery. There is a very simple way to implement a nice, clean solution which I bet you would prefer it to the Microsoft Update panel. My favorite is $.ajax() although there are more JQuery functions like $.getJson().
Lets walkthrough doing an Ajax call:
Step 1: Make a web service
You would need to write all of your database talk in some methods in a web service. You could pass parameters and return Json object. Webservice should be decorated with [ScriptService] and methods should with [ScriptMethod]
Step 2:
Add Script manager, reference your web service:
<asp:ScriptManager id="scriptManager" runat="server">
<Services>
<asp:ServiceReference Path="/MyWebservice.asmx" />
</Services>
</asp:ScriptManager>
you might leave the script manager in your master page and reference the JQuery library at the same place.
Step 3: Call your web service method using $.ajax():
function MyWebServiceMethod(parameter1, parameter2) {
$.ajax({
type: "POST",
url: "/MyWebService.asmx/WebMethod",
data: "{'parameter1':'" + parameter1 + "','parameter2':'" + parameter2+ "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.d == 0) {
//Do something
}
},
failure: function (msg) {
alert("There is an error...");
}
});
}
response.d == 0 means it is working properly. However response itself could be an object (Json object) which is returned by the webservice. So you can have for example response.Name, response.Price, etc.
JQuery is probably the most popular JavaScript library ever. I was facing a bad "time" requirement change tonight and that was poping up "Terms and Conditions" pop up as a mandatory option for registration. I just picked up fife minute solution:
You will need Fancy box (fancybox.net) but just whatch out to not overwriting JQuery references, they need to loaded sequentially and could easily drive you to a horrible nightmare!
1-Set References:
<link rel="stylesheet" type="text/css" href="Scripts/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.css" />
<script src="Scripts/jquery.fancybox-1.3.4/jquery-1.4.3.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.fancybox-1.3.4/fancybox/jquery.mousewheel-3.0.4.pack.js"
type="text/javascript"></script>
<script src="Scripts/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js"
type="text/javascript"></script>
<link href="Scripts/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.css" rel="stylesheet"
type="text/css" />
2-Within Document.Ready:
<script language="javascript" type="text/javascript">
$(document).ready(function () {
...
//if its just a peace of text within a hidden div
$("#various1").fancybox({
'titlePosition': 'inside',
'transitionIn': 'none',
'transitionOut': 'none',
});
//If you want to show the page with fully customised style
$("#v2").fancybox({
'titlePosition': 'inside',
'transitionIn': 'none',
'transitionOut': 'none',
'type' : 'iframe'
});
...
});
3-Call your grandmother, ask about combination of two kid, you and hell load of work in a weekend, she would guide you to the closest mental hospital...hang on, put your anchor tags somewhere :
<a id="various1" href="#inline1" >Inline</a> // usage of hidden div
<a id="v2" href="http://www.google.com" >Inline2</a> // loading in iFrame
4-Just make the hidden div:
<div style="display: none;">
<div id="inline1" style="width:400px;height:200px;overflow:auto;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis mi eu elit tempor facilisis id et neque. Nulla
sit amet se e vitae eleifend vel, iaculis sed magna. Aenean tempus lacus vitae orci posuere porttitor eget non feli
s. Donec lectus elit, aliquam nec eleifend sit amet, vestibulum sed nunc.
</div>
</div>
Note:
Div Id should be equal to href="#inline1" in Anchor tag
Anchor tag Id should be used: $("#various1").fancybox({});
If you get these ids confuse, I bet you will waste a box of red bull. Watch out!
Design Patterns sounds like an Italian recipies. If you you tell your grand mother that you cooked Bolognese and Pasta for evening, she wouldn't ask you how, as the recipie is famous enough to make scence to everyone. She wouldn't expect a creamy pasta with chicken unless you decided to make her surprise.
Same story when you coding. In fact the benefit of using Design Patterns is that when you say, for example, you have implemented Singleton, your work mate would have a picture of the code on spot and its make everyone's life much more easier.
One of the simplest one to start is Singleton. The usage is when you want to have a single instance of a class in the entire solution:
public class Singleton
{
private static Singleton instance;//Static variable to hold single instance
//Other variables...
//Private Constructor. So only Singleton can instantiate itself
private Singleton() { }
//Lazy instantiation (Never get created if doesn't needed)
public static Singleton Instance
{
get
{
if (instance == null)
{
instance = new Singleton();
}
return instance;
}
}
//Other Methods...
}
For some unknown reason I have decided to make some sausages with my pasta tonight and write couple of line about Class definitions in C#. I hated the smell of sausages and just decided to have my pasta with parmesan cheese and tomato sauce. It is really sucks when I am alone and need to cook something.
This is handy dandy to make some relation between C# class definitions and the design patterns actually. It is like making a relation between parmesan cheese and pasta, or perhaps between pasta and parmesan cheese. But because I am starving, I would probably leave the design patterns stuff to some next stage.
Abstract Class
Abstract class is a base class. It can not be instantiated. It is mainly used for inheritance. Abstract class may or may not have implementation. So a sub classes which are inheriting from main class can override methods and property of the main class.
public abstract class SampleClass
{
public abstract void SampleMethos(int param);
}
Overriding the methods:
public class SubClass : SampleClass
{
public override void SampleMethod(int param)
{
//[ToDo] implementation.
}
}
Abstract Class vs Interface
There is an absolute fact that Interface doesn’t have any implementation. But Abstract class, could have.
Remember the new Keyword. You could use it as a modifier to hide inherited member from the base class and provide new implementation.
Sealed Class
The concept is defining a class which no one can inherit from. It seled so it used to prevent inheritance. The usage might be the time that you have static members:
sealed class SampleSealedClass
{
public static int Multiply(int x, int y)
{
return x * y;
}
}
Static Class
A Class which can not be instantiated. It contains static members only. We might define private constructor for static class to be able to prevent automatic generation of default constructor.
static class SampleStaticClass
{
public static string GetSiteName() { return Constants.SiteName; }
}
Sealed vs Static Class
- Static Class cannot be instantiated but Sealed class can.
- Within Static class only static members are allowed. So static class can only have static constructor to initialize static members
- You can not inherit from either a Sealed class or a Static class
Partial Class
Partial keyword let you split up the class implementation. It is make a lot scene especially when a part of implementation has been generated by any ORM tool.
public partial class Products
{
public void GetProductByID()
{
//implementation
}
}
public partial class Products
{
public void GetProductByName()
{
//implementation
}
}
I love enums, they are organising my head, sometime you might need to traverse through all enum members for any reason. Say you would like to dynamically add controls to the form on the base of enum...
foreach (MyTypeEnum myType in Enum.GetValues(typeof(MyTypeEnum))
{
//myType.ToString()
}
Or say put all enum values in a list box
var lst = Enum.GetValues(typeof(MyTypeEnum)).OfType<MyTypeEnum>()
.Select(o => new ListItem { Text = o.ToString(),
Value = ((int)o).ToString() });
myList.Items.AddRange(lst.ToArray());
How cool is that?
sometime, you might want to convert your string value back to enum, or actually you want to do parsing:
MyTypeEnum role = (MyTypeEnum) Enum.Parse(typeof(MyTypeEnum), roleString);
This HttpContext is is a very useful creature, look at this one:
HttpContext.Current.Request.Url.AbsolutePath
For example you might want to change a CSS class of a control at runtime depend to url, you could specify this code in the master page and observe the url in the PageLoad for say.
Empty data in repeater doesn't have a template. Have a look at this:
if (rptMyRepeater.Items.Count < 1)
{
if (e.Item.ItemType == ListItemType.Footer)
{
Label lblFooter = (Label)e.Item.FindControl("lblEmpty");
lblFooter.Visible = true;
}
}
I found the above code is usefull if you need to show something like "There is no record" is your data source has no records. Although the ListView has a template.
Wish you ever validate the page using .NET validation controls in JS for any reason? Just use Page_ClientValidate in a javascript function or something.
Page_ClientValidate('ValidationGroupName');
I got stocked passing parameter to one master page for some reasons, seems the page lifecycle and dynamic loading of the master pages has got some issues with defining public properties in the masterpage within my project. It did not set my values and as a result, properties became useless.
A collegue just mentioned using HttpContext. have a look what MSDN saying "Encapsulates all HTTP-specific information about an individual HTTP request" http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx
HttpContext.Current.Items["ParameterName"]
Also, Page.Items could do the same thing. Page.Items, "Gets a list of objects stored in the page context" http://msdn.microsoft.com/en-us/library/system.web.ui.page.items.aspx as your master page and content page are rendered as a single document anyway.