Showing posts with label Asp.net. Show all posts
Showing posts with label Asp.net. Show all posts

Sunday, October 25, 2009

Open a New Window On Server Side using Javascript Code in Asp.net

· 1 comments

// open new window with specified path

function OpenWindow(url)

{
newwindow = window.open(url, 'mywindow', 'width=500,height=400');

}

Now In .aspx.cs page or server side to use the javascript window open you have to use the following code

StringBuilder popupScript = new StringBuilder();
popupScript.Append("");
// if you are using script manager - update panel then this
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "PopupScript", popupScript.ToString(), false);
//else
Page.RegisterStartupScript("PopupScript", popupScript.ToString());

Read More......

Saturday, October 24, 2009

Add "Select" Option To Dropdown list in Asp.net

· 0 comments

There are many ways to add select option to dropdown list.. Here in this post i will list some of the ways: 1) Select 2) ddltemp.Items.Add(new ListItem(”Select”, “0")); 3) ddltemp.Items.Insert(0, new ListItem(”Select”, “0")); 4) ddltemp.Items.Insert(0, "--Select--"); ddltemp.Items[0].Value = "0";

Read More......

Friday, September 11, 2009

Tutorial using MySQL with Asp.Net

· 0 comments

If you want to use MySQL Database with Asp.net, then here is a link which explains: http://www.15seconds.com/issue/050407.htm

  • Download of MySQL Server
  • MySQL Administrator
  • MySQL Query Browser
  • .Net Connector (For Asp.net Integration)
The above link has explained in detail, with proper screenshots, from where to download installers, how to install with step by step screens and explanations, and also how to create sample asp.net application with MySQL database, create MySQL database (schema), create MySQL Table, Insert Data, and populate that data in asp.net gridview.

Read More......

Wednesday, September 9, 2009

Using String.Format("{0}", "formatting string"}; in Asp.net

· 0 comments

Many times we want to define formats for date, currency, number etc

For example if we want date in

" 09 September 2009"  - String.Format{0:D}

" 09 September 2009 12:30"  - String.Format{0:f}

Like this various formats for date, month, year, time, currency number etc can be seen at :

http://bit.ly/cctp


Read More......

Monday, August 31, 2009

Textbox Watermark using Ajaxtoolkit or By Javascript

· 0 comments

Adding Watermark to textbox can be done in two ways:

1) Using Ajax Toolkit:

<asp:TextBox runat="server" id="txtname"/>
<ajaxToolkit:TextBoxWatermarkExtender ID="TBWE2" runat="server"
TargetControlID="TextBox1"
WatermarkText="Type First Name Here"
WatermarkCssClass="watermarked" />

For more information on Ajax Toolkit please visit:
http://www.asp.net/ajax/

2) Using Javascript
:

<asp:TextBox ID=”txtname” runat=”server” Text = “Please Enter your Name here”
onblur = “TextboxWaterMark(this, event);”
onfocus = “TextboxWaterMark(this, event);”>
</asp:TextBox>

<script type = “text/javascript”>
var Text = “Please Enter your text here”;//black

function TextboxWaterMark(txtid, evnt)
{
if(txtid.value.length == 0 && evnt.type == “blur”)
{
txtid.style.color = “set the color you want”;//red
txtid.value = Text;
}
if(txtid.value == Text && evnt.type == “focus”)
{
txtid.style.color = “set the color you want”;
txtid.value=”";
}
}
</script>

To use in code behind :

txtname.Attributes.Add(”onblur”, “TextboxWaterMark(this, event);”);

txtname.Attributes.Add(”onfocus”, “TextboxWaterMark(this, event);”);

Read More......

Friday, August 28, 2009

Disable button after submit in Asp.net

· 0 comments

Once the user has filled the form details, or did any kind of changes and clicked on submit button, if we want to prevent the duplicate data entry and show other message like "please wait.."'then we can do this as below:

<asp:Button  runat="server" ID="btnsubmit" Text="Submit"
OnClick="btnsubmit_Click" UseSubmitBehavior="false"
OnClientClick="this.disabled=true;this.value='Please wait..';" />

For <asp:imagebutton> usesubmitbehavior will not work hence for this:

<asp:ImageButton runat=”server” ID=”btImageButton”
ImageUrl=”/images/submit.jpeg” OnClick=”btImageButton_Click”
OnClientClick=”javascript: Submit(this);” />

<script type=”text/javascript” language=”javascript”>

function Submit(c){
Page_ClientValidate();
if (Page_IsValid){
c.disabled = true
__doPostBack(c.name, ”);
}
return Page_IsValid;
}

</script>


For furhter reference please visit msdn : http://bit.ly/1CpMBq

Read More......

Wednesday, August 26, 2009

Preview/Show Uploaded Image in Asp.net

· 0 comments

Sometimes, we want to give the preview of the image uploaded through file upload control in asp.net, at the same time.

There is a very nice article on this.. using server side.

http://dotnetspider.com/resources/31341-Show-Uploaded-Image-Image-Control-Asp-net.aspx

In this article, we have one image control, one file upload control and one button control

We upload image using file upload control, and then click on upload button, at the same time the image uploaded will be shown in the image control..

Read More......

Saturday, August 22, 2009

Changing Css Class or Style At Run time dynamically in Asp

· 0 comments

You can add/change css style or add new attributes to current style at runtime, in asp.net code behind.

Lets say you have:

Download

Now if we want to change its class dynamically then in code behind we have to do:

linktemp.Attributes.Add(”class”, “verdana13greynormalitalic”);

if we want to change its text-decoration under style then,

linktemp.Style.Add(”text-decoration”, “none”);

in the similar you can add new styles, change visible option to true/false,

linktemp.Style.Add(”display”, “block”);

Read More......

Thursday, August 20, 2009

Limiting the number of records to be displayed in Crystal Report

· 0 comments

You might be working with crystal reports, and so must have a noticed that number of records displayed in crystal report are variable, sometimes, it displays 8, sometimes 10.. and so on according to the data, it sets it accordingly.

But we can handle this scenario i.e we can specify how many records we want the crystal report to display. For this you need to follow the below instructions:

To make it show 10 records per page do the following

1. Open the report in Design View

2. Right click on the Details section and select Section Expert

3. Make sure the Details section is selected in the Section Expert dialog box. Check the box that says “New Page After”

4. Click the formula editor button to the right of the checkbox.

5. Enter the following formula

if Remainder (RecordNumber, 10) = 0 then true else false

6. Click Save and Close and then click OK.

If you run the report it should break after each 10 rows.

Read More......

Friday, June 26, 2009

CRUD(Create/Insert/Update/Delete) with Asp.net MVC Framework, Linq To Sql (.dbml)

· 0 comments

This article will explain you how to create, read, insert, update, delete operations with asp.net mvc with Linq To Sql (.dbml).

Very nice article who are beginners with asp.net mvc framework.

http://blogs.microsoft.co.il/blogs/bursteg/archive/2009/02/03/create-a-strongly-typed-crud-ui-with-asp-net-mvc-rc.aspx

Read More......

Thursday, June 25, 2009

CRUD(Create/Insert/Update/Delete) with Asp.net MVC Framework, ADO.Net Entity Data Model

· 0 comments

This article will explain you how to create, read, insert, update, delete operations with asp.net mvc with ado.net entity model.


Very nice article who are beginners with asp.net mvc framework.


http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/AuthorContactManager06102009052732AM/AuthorContactManager.aspx

Read More......

Wednesday, June 3, 2009

Implementing Search in ASP.NET with Google CustomSearch

· 0 comments

Going to add search functionality for your website... why not let google do this task.. it would be easier and user friendly..

With those who are unaware of Google Custom Search :
"With Google Custom Search, you can harness the power of Google to create a customized search experience for your own website"


  • Include one or more websites, or specific webpages

  • Host the search box and results on your own website

  • Customize the look and feel of the results to match your site


For more info on google custom search click here

So lets see how to implement search in asp.net with google custom search..

Here is the step by step procedure very nicely explained in the below article..

http://dotnetslackers.com/articles/aspnet/Implementing-Search-in-ASP-NET-with-Google-Custom-Search.aspx

Read More......

Monday, June 1, 2009

Adding eWorld.UI (Excentrics World) Calendar Popup, TimePicker.. etc in Asp.net

· 0 comments

You might be in need of Calendar popup or Time Picker in asp.net. I have being using eworld's calendar popup and time picker control since many years.. and all i can say that they are fantastic fully loaded with various features... No Need of taking a textbox and a calendar control for binding date.. and adding different validations for valid date, past and future date validation... now all that comes in one place just drag and drop one calendar popup control and it will give you access to multiple features..

Also there is no time picker control available in our asp.net toolbox.. i searched a lot over the internet and i found this one..

You can download the eworld ui toolkit from :

http://www.eworldui.net/Download.aspx

Toolkit is available for various .net versions whether it is 1.0, 2.0 or 3.5

Once Downloaded, unzip the rar file and install the given exe..

Also, Once done copy the eWorld.UI.dll and paste it in the bin folder of your web application and then right click the web site and add reference of that dll.

Then In the Visual Studio ->View ->Tool box -> Right Click ->Add Tab -> give Eworld Toolkit (as name) - > Right click ->choose items and browse to the eworld ui dll and once done you will see many contorls under that tab in the tool box..

I have been using

CalendarPopup

Time Picker

RangeValidator

CustomValidator

MaskedTextbox...

there are lots of other controls too which you can try at your lease..

Once done.. you can drag and drop the calendar popup on to the aspx page and you will see:

<ew:CalendarPopup ID="tb_startupdate"
runat="server" ControlDisplay="TextBoxImage" ImageUrl="~/Images/dtpicker.jpeg">
</ew:CalendarPopup>

Read More......

Sunday, May 31, 2009

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

· 0 comments

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/

Read More......

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

· 0 comments

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)$





Read More......

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

· 0 comments

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" />

Read More......

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

· 0 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


Read More......

Call a C# Method from aspx Page

· 0 comments

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;

}

Read More......

Friday, May 29, 2009

Validating Checkboxlist using CustomValidator

· 11 comments

You might be knowing that required field validator doesn't works with required field validator... so to accomplish that purpose we can use custom validator to validate checkbox list.

<asp:CheckBoxList ID="chkModuleList"runat="server" >
</asp:CheckBoxList>




1) Using ClientValidationFunction


<asp:CustomValidator runat="server" ID="cvmodulelist" ClientValidationFunction="ValidateModuleList" ErrorMessage="Please Select Atleast one Module" ></asp:CustomValidator>

function ValidateModuleList(source, args)
{
var chkListModules= document.getElementById ('<%= chkModuleList.ClientID %>');
var chkListinputs = chkListModules.getElementsByTagName("input");
for(var i=0;i<
chkListinputs .length;i++)
{
if(
chkListinputs [i].checked)
{
args.IsValid = true;
return;
}
}
args.IsValid = false;
}

2) Using OnServerValidate


<asp:CustomValidator runat="server" ID="cvmodulelist" OnServerValidate="ValidateModuleList" ErrorMessage="Please Select Atleast one Module" ></asp:CustomValidator>

private void ValidateModuleList(object sender, ServerValidateEventArgs e)
{
int cnt= 0;


for(int i=0;i<chkModuleList.Items.Count;i++)
{
if(
chkModuleList.Items[i].Selected)
{
cnt++;
}


e.IsValid = (cnt== 0) ? false : true;
}
}



Read More......

Wednesday, May 27, 2009

Reset/Clear all fields - Textbox/Dropdown/Radionbuttonlist/Listbox etc of a web form in Asp.net

· 0 comments

In most of the case after inserting data into database or carrying out any other transactions. in which we have one form that contains bunch of textbox's, radiobuttonlist, checkboxlist, dropdownlist, checkbox, listbox etc or any other controls in asp.net .now after inserting data, on submit/save click we want to empty/reset/clear all controls in the web form, we actually do like this:

txtid.text ="";
ddid.SelectedIndex = -1;


and so on... and that for each textbox, dropdowns... etc it becomes very tedious and long.. so to make it short we should create a common function to reset all controls in web form...

Here is the ready made function :

Step 1:

///
/// Pankaj lalwani
/// Reset all textbox/radiobutton/dropdowns/listbox
///
///
public static void ClearFields(ControlCollection pageControls)
{
foreach (Control contl in pageControls)
{
string strCntName = (contl.GetType()).Name;
switch (strCntName)
{
case "TextBox":
TextBox tbSource = (TextBox)contl;
tbSource.Text = "";
break;
case "RadioButtonList":
RadioButtonList rblSource = (RadioButtonList)contl;
rblSource.SelectedIndex = -1;
break;
case "DropDownList":
DropDownList ddlSource = (DropDownList)contl;
ddlSource.SelectedIndex = -1;
break;
case "ListBox":
ListBox lbsource = (ListBox)contl;
lbsource.SelectedIndex = -1;
break;
}
ClearFields(contl.Controls);
}
}


Step 2:
Call this method on submit/save click after your code ends or sometimes when you provide clear/reset button to empty all fields


ClearFields(Form.Controls);

Read More......