Archive

Archive for May, 2009

Call a C# Method from aspx Page

May 30, 2009 1 comment

Sometimes you need to call a method written in codebehind(.aspx.cs) from .aspx page.

Here is a simple example:

In your aspx page

<asp:Label ID=”lbllable” runat=”server” text='<%# GetCustomerID() %>’ />
In your codebehind(.aspx.cs) page

  1. private string _CustomerID = “8888”;
  2. protected void Page_Load(object sender, EventArgs e)
  3. {
  4. lbllable.DataBind();
  5. }
  6. public string GetCustomerID
  7. {
  8. get { return this._CustomerID; }
  9. }

When you are using in gridview or any other data bound control then

in your aspx page
<%# GetEmployee(Eval(“EmpId”))%>

in your codebehind

public object GetEmployee(object EmpId)
{

EmpId = 1234;
return EmpId;
}

Advertisements

Read/Acess globalization section of system.web from web.config

May 30, 2009 2 comments

To read web.config, and find any section there are number of solutions available, one such method to access globalization section which is under system.web of web.config is as follows:

In web.config i have

<globalization uiCulture=”nl-NL”   />

Now to read the uiculture in codebehind file in asp.net

string uicul = ((System.Web.Configuration.GlobalizationSection)(System.Configuration.ConfigurationSettings.GetConfig(“system.web/globalization”))).UICulture;

Lets say for example i have to display date  according to culture set in web.confg so:

public object GetDateCulture(object date)
{
string uicul = ((System.Web.Configuration.GlobalizationSection)(System.Configuration.ConfigurationSettings.GetConfig(“system.web/globalization”))).UICulture;
System.IFormatProvider format = new System.Globalization.CultureInfo(uicul, true);
date = Convert.ToDateTime(date).ToString(“dd MMM yyyy”, format);
return date;
}

Ouput will be:

if culture is english : 22 May 2009

if culture is dutch : 22 Mai 2009


Set meta tag in asp.net programmaticaly for seo friendly websites

When you are developing SEO friendly websites, the first basic thing for seo is meta tags, as all search engines are looking for these meta tags while querying the database. Here we will allow the user to set the “keywords” and “description” (the two parts of meta tag)and then set the meta tag programmatically.

This is how meta tags are set dynamically:

HtmlMeta mKey = new HtmlMeta();
mKey.Name = “keywords”;
mKey.Content = “home, blog”;
this.Page.Header.Controls.Add(mKey);

HtmlMeta mdesc = new HtmlMeta();
mdesc.Name = “description”;
mdesc.Content =”home page”;
this.Page.Header.Controls.Add(mdesc);

after doing that you can view in the “View Source” of the page you have set meta tags under the head section.

<meta name="keywords" content="home,blog" />
<meta name="description" content="home page" />

Validating Extension(eg. (.aspx/.html/.jpeg….) in asp.net using Regular Expression

May 30, 2009 1 comment

When you want to validate that the text entered must have particular extension that you have decided.

for example if you have a textbox to enter page name. You want the user to enter page name with “.aspx” extension. Then you have to use the following regular expression validator.
<asp:RegularExpressionValidator ErrorMessage=” Please Enter page name with .aspx extension”
ID=”RegularExpressionValidator1″ runat=”server”
ValidationExpression=”^.*\.(aspx)$” ControlToValidate=”txturl” Display=”Dynamic” ></asp:
RegularExpressionValidator >

so now if the user enters “hello.abc” then validation will fire with message “Please enter page name with .aspx extension”

Thus with this ValidationExpression=”^.*\.(aspx)$”

you can specify any extension like gif, jpeg or whatever you want..

^.*\.(exe|bat|etc)$



Download Ajax Loading Image

May 30, 2009 1 comment

Since all the Ajax interactions happen behind the scenes asynchronously, the user doesn’t understand what’s going on: sometimes the user doesn’t need to know what’s going on (like when you are just reloading some data), but when he presses a button he needs to know that he did the right thing and that something is happening.

So we can show an “ajax loading image” when ajax process is going on..

You can generate these images from:

http://www.ajaxload.info/

You can also download from:

http://mentalized.net/activity-indicators/

Also you can search the google for ajax loading image and you will be able to see lots of images..

Categories: Ajax Tags: , ,

Download Cheatsheets – .Net, Sql Server, Php, Regular Expressions, CSS, Ajax,Javascript….

A cheat sheet or crib sheet is a concise set of notes used for quick reference.

You can download cheatsheets of various technologies like:

.Net

Actionscript

Ajax

Javascript

C#

HTML

Sql Server

CSS

JAVA

PHP

Regular Expressions

MySql

Asp/Vbscript

etc..

from

http://www.addedbytes.com/cheat-sheets/

http://www.cheat-sheets.org/

SQL SERVER – Fix : Management Studio Error : Saving Changes in not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created

I encountered problem when modifying table in SQL Server 2008, Once the table is created open the table in SSMS by clicking on the table name and selecting “Design.” Try to include another column to the existing table and click on save (CTRL+S). It will prevent it from saving and will emit the following error in popup.
Saving Changes in not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created

i searched the internet.. i got solution from pinal dave’s blog

http://blog.sqlauthority.com/2009/05/18/sql-server-fix-management-studio-error-saving-changes-in-not-permitted-the-changes-you-have-made-require-the-following-tables-to-be-dropped-and-re-created-you-have-either-made-changes-to-a-tab/

Categories: Sql Server Tags: