Thursday, October 7, 2010
Dynamically Add a Control to the Page From a User Control
actualy this can't be done this way, because at this stage the page has loaded all the controls to build and it can't be modiified at this point as per the error message,you can do the following:
1- in the control page_load function place this line
this.Page.LoadComplete+=new EventHandler(addcont); // adds a function to the vent handler to be done after the page completes the loading
2- add this function which is used in the event handler above inside your control :
public void addcont(Object obj, EventArgs e)
{
Label newlable = new Label();
newlable.Text = "TestText here";
newlable.BackColor = System.Drawing.Color.Red;this.Page.Form.Controls.Add(newlable);
}
inside this function write all the controls you want to add to the page, this here adds a lable with a red background, with some test text in it..
I hope this helps,
please do not forget to mark my post as answer if it helps...
have a nice day,
Create Table From Class Files With There Propertys/ Convert GenericList to DataTable
private DataTable GetDataTable(PageEntriesInfo _PageInfo)
{
var dt = new DataTable();
foreach (var Info in typeof(CustomElementInfo).GetProperties())
{
dt.Columns.Add(new DataColumn(Info.Name, Info.PropertyType));
}
foreach (var t in _PageInfo.CustomElements)
{
//CustomElements are SubCategory List
var row = dt.NewRow();
foreach (var Info in typeof(CustomElementInfo).GetProperties())
{
row[Info.Name] = Info.GetValue(t, null);
}
dt.Rows.Add(row);
}
return dt;
}
Monday, October 4, 2010
4 steps to increase bandwidth performance for ASPX pages on IIS 6.0
Step 2:- Enable metabase.xml edit
Step 3:- Set the compression level and extension types
Step 4:- Does it really work?Introduction and warning
In this article we will try to understand how to enable compression on IIS 6.0. Once we have enabled compression we will use fiddler to see how bandwidth performance increases due to the same.
Please feel free to download my free 500 question and answer eBook which covers .NET , ASP.NET , SQL Server , WCF , WPF , WWF@ http://www.questpond.com .
Do not jump to a conclusion
As I have clearly mentioned this article will form the base for my 4th article on .NET best practices. So please do not jump to a conclusion and enable IIS compression on production servers. There are issues of CPU performance, compression levels and browser compatibility due to IIS compression enablement. I will be talking about those details later. For now we will just concentrate on how to enable IIS compression and how does it increase bandwidth performance.
Step 1:- Enable compression
The first step is to enable compression on IIS. So right click on websites ? properties and click on the service tab. To enable compression we need to check the below two text boxes from the service tab of IIS website properties. Below figure shows the location of both the checkboxes.
Step 2:- Enable metabase.xml edit
Metadata for IIS comes from ‘Metabase.xml’ which is located at “%windir%\system32\inetsrv\”. In order that compression works properly we need to make some changes to this XML file. In order to make changes to this XML file we need to direct IIS to gives us edit rights. So right click on your IIS server root ? go to properties and check ‘enable direct metabase edit’ check box as shown in the below figure.
Step 3:- Set the compression level and extension types
Next step is to set the compression levels and extension types. Compression level can be defined between 0 to 10, where 0 specifies a mild compression and 10 specifies the highest level of compression. This value is specified using ‘HcDynamicCompressionLevel’ property. There are two types of compression algorithms ‘deflate’ and ‘gzip’. This property needs to be specified in both the algorithm as shown in the below figures.

We need to also specify which file types need to be compressed. ‘HcScriptFileExtensions’ help us to specify the same. For the current scenario we specified that we need to compress ASPX outputs before they are sent to the end browser.
Step 4:- Does it really work?
Once you are done with the above 4 steps, it’s time to see if the compression really works. So we will create a simple C# asp.net page which will loop “10000” times and send some kind of output to the browser.
protected void Page_Load(object sender, EventArgs e)
{
for (int i; i <>
In order to see the difference before compression and after compression we will run the fiddler tool as we run our ASP.NET loop page. You can download fiddler from http://www.fiddler2.com/fiddler2/version.asp .Below screen shows data captured by fiddler without compression and with compression. Without compression data is “80501 bytes” and with compression it comes to “629 bytes”. I am sure that’s a great performance increase from bandwidth point of view.
Assign Value to Asp.Net TextBox with mode="Password"
Introduction
ASP.NET server control doesn't add/display the value in a password textbox because of security concerns. On most of the web sites at the time of registration password is asked. You must have noticed after submitting the page if you are again redirected to the page due to unsuccessful registration value of password field is lost.This is due to security concerns as everything is gets rendered on the client side So when you view the source in the browser password value will be there.
Solution 1
Add an attribute to textbox.Add this following line of code when you want set the value
TextBox1.Attributes.Add("value", "thePassword")Above solution will work, but if a user does view source on the form, the password is visible as plain text and that is never good from a security point of view. Rather, I would use Viewstate to hold the password value and if the user doesn't change it then retrieve the value from view state. Solution 2
But if explicitly you want to set the value of password text box again then use following method in .NET 2.0
txtPassword.Attributes["value"] = Request.Form[txtPassword.ClientID]; //in C#.Net 2.0Enjoy..
Alt+ Shortcut keys
All you need to do is Hold down your "ALT" key and press another key on the keyboard to create a symbol.
Here is a list of some you can make. Have Fun!!
· Alt + 0153 - Trademark symbol
· Alt + 0169 - Copyright symbol
· Alt + 0174 - Registered trademark symbol
· Alt + 0176 - Degree symbol
· Alt + 0177 - Plus-or-minus sign
· Alt + 0182 - Paragraph mark
· Alt + 0190 - Fraction, three-fourths
· Alt + 0215 - Multiplication sign
· Alt + 0162 - The cent sign
· Alt + 0161 - Upside down exclamation point
· Alt + 0191 - Upside down question mark
· Alt + 1 - Smiley fsce
· Alt + 2 - Black smiley face
· Alt + 15 - Sun
· Alt + 12 - Female sign
· Alt + 11 - Male sign
· Alt + 6 - Spade sign
· Alt + 5 - Club symbol
· Alt + 3 - Heart
· Alt + 4 - Diamond
· Alt + 13 - Eighth note
· Alt + 14 - Beamed eighth note
· Alt + 8721 - N-ary summation (auto sum)
· Alt + 251 - Square root check mark
· Alt + 8236 - Infinity
· Alt + 24 - Up arrow
· Alt + 25 - Down arrow
· Alt + 26 - Right pointing arrow
· Alt + 27 - Left arrow
· Alt + 18 - Up/down arrow
· Alt + 29 - Left right arrow
.
Thursday, September 30, 2010
Google Map in Asp.Net
Introduction
In this article, We are going to Implement Google Map using Asp.net Custom control. It Offers extremely easy and fast way of adding Google Maps API support on your ASP.NET pages.Lets go through this application step by step
Step 1:
Create a new website >select the programming language as c#> Name the project as GoogleMap
Step 2:
Now lets go to this site and download the DLL from the Recommended download
http://googlemap.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=26521
Step 3:
Now i think that you people have download that ddl.. Now right click on to the website and add reference to arthem.GoogleMap.
Step 4:
Now add this in the Web.config under Pages tag and under Controls.

Step 5:
Now go to this site and give your URL in click on Generate API Key.
http://code.google.com/apis/maps/signup.html
Copy this Key and paste in some document..
Step 6:
Now add this lines of lines of code in .aspx page

We are using Google Marker to indicate your location. Zoom can be set until 9.
Step 7:
Now Lets run this application.. Output will be displayed like this

Download Complete Code
When JavaScript Disabled then redirect noscript page
<h6> Step1</h6>
create a page where you want to redirect user when JavaScript is disabled. Say we created a page "noscript.aspx". See below code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
document.location.href = "Login.aspx";
</script>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<div style="text-align: center; color: Red; font-family: Calibri; font-size: 12pt; width:400px">
<b>* JavaScript Need To Be Enabled To visit Requested page.</b>
</div>
</div>
</form>
</body>
</html>
User will land on this page when any page is requested with disabled javascript. Specify , on which page you want to redirect user when javascript is enabled in "script>" tag.
<h6>Step2</h6>
In main master page of your site write <noscript> tag.Specify URL = noscript.aspx page we have created.Meta tag will redirect user to given URL (noscript page in this case) when javascript is disabled.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<noscript>
<meta http-equiv="refresh" content="0;URL=noscript.aspx" />
</noscript>
</body>
</html>
Run the application and test it. :)