RSS

Monthly Archives: September 2010

Select All Text in ASP.NET Text Box or Highlighting the text in a textbox when it gets focus


How do I select all the text in a .Net text box when user clicks in that box to type information?

I have a text box, txtContractorId that has “Enter Id Here” in it by default. When the click in that box I want to select all the text so they can just start typing

In page load:
C#:
TextBox1.Attributes[“onmouseover”] = “javascript:this.focus();”;
TextBox1.Attributes[“onfocus”] = “javascript:this.select();”;

VB:
TextBox1.Attributes(“onmouseover”) = “javascript:this.focus();”
TextBox1.Attributes(“onfocus”) = “javascript:this.select();”

Advertisements
 
Leave a comment

Posted by on September 23, 2010 in ASP Dot Net C#

 

HTML Entities-Currency Symbol


Reserved characters in HTML must be replaced with character entities.


Some characters are reserved in HTML.

It is not possible to use the less than (<) or greater than (>) signs in your text, because the browser will mix them with tags.

&entity_name

;

OR

&#entity_number;

To display a less than sign we must write: &lt; or <

Non-breaking Space

A common character entity used in HTML is the non-breaking space (&nbsp;).

Browsers will always truncate spaces in HTML pages. If you write 10 spaces in your text, the browser will remove 9 of them, before displaying the page. To add spaces to your text, you can use the &nbsp; character entity.

For Test Online Result:

http://www.w3schools.com/HTML/html_entities.asp

HTML Useful Character Entities

Note: Entity names are case sensitive!

Result Description Entity Name Entity Number
non-breaking space &nbsp;  
< less than &lt; <
> greater than &gt; >
& ampersand &amp; &
¢ cent &cent; ¢
£ pound &pound; £
¥ yen &yen; ¥
euro &euro;
§ section &sect; §
© copyright &copy; ©
® registered trademark &reg; ®
trademark &trade;
 
Leave a comment

Posted by on September 22, 2010 in ASP Dot Net C#

 

How to Add currency Symbol in Gridview Price/Amount Column


A.A…………

If you want to add currency symbol in gridview column. dynamically change the symbol of currency just you need the symbol in web.config file and automatically change the symbol in gridview…….

Solution:

Gridview formate

————————————————————–

<asp:GridView ID=”GVInstallment” runat=”server” AutoGenerateColumns=”False” DataKeyNames=”InstallmentID”
OnRowDeleting=”GVInstallment_RowDeleting” Width=”100%” OnRowDataBound=”GVInstallment_RowDataBound”>
<Columns>
<asp:TemplateField HeaderText=”Amount”>
<ItemTemplate>
<asp:Label ID=”lblAmountgv” runat=”server” Text='<%# Bind(“Amount”) %>’></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField=”DueDate” DataFormatString=”{0:d}” HeaderText=”Due Date” />
<asp:BoundField DataField=”Status” HeaderText=”Status” />
<asp:TemplateField HeaderText=”Action”>
<ItemTemplate>
<asp:Button ID=”btnDelte” runat=”server” CommandName=”Delete” SkinID=”Delete” />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<center>
<asp:Label ID=”lblEmptyGV” runat=”server” Font-Bold=”True” ForeColor=”White” Text=”No Records Found of Installment”></asp:Label></center>
</EmptyDataTemplate>
</asp:GridView>

—————————————————————-

Currency Symbol use in Web.Config File

<add key=”Currency” value=”£”/>

Access in Code behind File where we use this symbol

Declare the variable.

public static string CurrenceSymble = string.Empty;

Write this code on page load and use this namespace

using System.Configuration;

CurrenceSymble = ConfigurationManager.AppSettings.Get(“Currency”);
lblRegFeeCrSybble.Visible = true;
lblRegFeeCrSybble.Text = CurrenceSymble;

Write this code Gridview Event on RowDataBound

protected void GVInstallment_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// add the UnitPrice and QuantityTotal to the running total variables
priceTotal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, “Amount”));
((Label)e.Row.FindControl(“lblAmountgv”)).Text =lblRegFeeCrSybble.Text + ‘ ‘ + priceTotal;

}

//if(e.Row.RowType == DataControlRowType.DataRow)

//       ((Label)e.Row.FindControl(“lblAmountgv”)).Text  =((DataRowView)e.Row.DataItem)[“Amount”].ToString();

}

—————————————————————–

———————Complete—————————————————————

Second  Tutorial which also very help full

How to format GridView Rows/Columns in Design/Run time

First of All if you use static or hard code use when you need only one formate then use default method.

Here i will discuss how you can format data in GridView rows. Most of the time we require to render our GridView control by custom formatting since data source format does not contain our exact required formats. Like, you want to display numeric values in two decimal format or want to display short date instead of considering time portion from databse. In this post i will try to resolve below issues:

*** How to format date/numeric data in GridView in design time
*** How to format data in GridView in run time/code behind
*** How to format Template Column
*** How to use DataFormatString property to format data
*** What is HtmlEncode?

Format character Description Pattern Example
d Short date MM/dd/yyyy 12/1/2009
D Long date dddd, dd MMMM yyyy Sunday, April 12, 2009
t Short time HH:mm 5:12 PM
T Long time HH:mm:ss 5:12:00 PM
f Full date/time(short time) dddd, dd MMMM yyyy HH:mm Sunday, April 12, 2009 5:12 PM
F Full date/time(long time) dddd, dd MMMM yyyy HH:mm:ss Sunday, April 12, 2009 5:12:00 PM
g General date/time(short time) MM/dd/yyyy HH:mm 4/12/2009 5:12 PM
G General date/time(long time) MM/dd/yyyy HH:mm:ss 4/12/2009 5:12:00 PM
m or M Month day MMMM dd April 12
r or R GMT ddd, dd MMM yyyy HH’:’mm’:’ss ‘GMT’ Sun, 12 Apr 2009 7:12:00 GMT
s Sortable date/time yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss 2009-04-12T14:12:00
u UniversalSortableDateTimePattern using universal time yyyy’-‘MM’-‘dd HH’:’mm’:’ss’Z’ 2009-04-12 14:12:00z
U Full date and time (long date and long time) using universal time dddd, dd MMMM yyyy HH:mm:ss Sunday, April 12, 2009 10:12:00 PM
y or Y Year month MMMM yyyy April, 2009
Format date in bound column:

Consider we have a GridView that displays Supplier information with Code, Name, Address, Contact no and Supply date where the Supply date is stored with time in database. To do that for bound column apply the below technique:

<

asp:BoundField DataField=”LastDelivery” HeaderText=”Recent Delivery” DataFormatString = “{0:y}” HtmlEncode=”false”></asp:BoundField>

OR

<

asp:BoundField DataField=”LastDelivery” HeaderText=”Recent Delivery” DataFormatString = “{0:MMMM yyyy}” HtmlEncode=”false”></asp:BoundField>

If you want to format date using SQL query then Click Here.

i.e. You can use both format or pattern column to format date column like below:

Formatting columnar data in a GridView code-behind:

protected void gvEdit_RowDataBound(object sender, GridViewRowEventArgs e)
{if (e.Row.RowType == DataControlRowType.DataRow)
{e.Row.Cells[4].Text = Convert.ToDateTime(((DataRowView)e.Row.DataItem)[“LastDelivery”]).ToString(“y”);
}
}

Format Template Column:
Add a template column with textbox/label etc.. then format it in the below way:

<

asp:TemplateField HeaderText=”Recent Delivery”>
<ItemTemplate><asp:Label ID=”lbl” runat=”server” Text='<%# Eval(“LastDelivery”, “{0:y}”) %>’></asp:Label>
</ItemTemplate></asp:TemplateField>

List of Numeric Formats:

Format Description Example
C Currency format $10.00
D Decimal format 10
E Scientific format 1.000000E+001
F Fixed format 10.00
G General format 10
N Number format 10.00
X Hexadecimal format A

Note: Format characters are not case-sensitive, except for “X”

The value after the format character specifies the number of significant digits or decimal places to display. For example, the formatting string “{0:F2}” displays a fixed-point number with two decimal places.

Format numeric data in bound column:

<

asp:BoundField DataField=”Price” HeaderText=”Price” DataFormatString=”{0:C2}” HtmlEncode=”false”>

Format numeric data in Template Column:

<

asp:TemplateField HeaderText=”Recent Delivery”>
<ItemTemplate>
<asp:Label ID=”lbl” runat=”server” Text='<%# Eval(“Price”, “{0:C2}”) %>’></asp:Label>
</ItemTemplate>
</asp:TemplateField>

Formatting columnar data in a GridView code-behind:

protected void gvEdit_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
((Label)e.Row.FindControl(“lbl”)).Text = Convert.ToDecimal(((DataRowView)e.Row.DataItem)[“ID”]).ToString(“C5”);
}

You may need to add few prefix like AU/US then use :
DataFormatString=”AU {0:C5}” HtmlEncode=”false”
OR
DataFormatString=”US {0:C5}” HtmlEncode=”false”

NOTE: Most of the beginner forget to add HtmlEncode=”false”

What is HtmlEncode?
Microsoft introduced this new property to prevent cross site scripting (CSS) attacks. This way if there is any malicious text in the fields, it will get encoded and will not executeon client’s browser. If this property is set to true, the formatting implementation in the control first encoded the text using HttpUtility.HtmlEncode. And after that it calls String.Format method on the encoded text value.Where as when HtmlCode is set to false, the formatting is done on the data value itself. So the way to fix your problem with formatting would be to set HtmlEncode property to false.


 
7 Comments

Posted by on September 21, 2010 in ASP Dot Net C#

 

Textbox to allow integer only


You should look at using a RegularExpressionValidator. Validator may ASPX page, which you control with the strengthening of property ControlToValidate

Code;

  <asp:RegularExpressionValidator id="RegularExpressionValidator1" 
                     ControlToValidate="TextBox1"
                     ValidationExpression="^\d+$"
                     Display="Static"
                     ErrorMessage="value must be an integer"
                     runat="server"/>


n your button you would set the CausesValidation property to true.



<asp:Button ID="SomeButton"
                    Text="Submit"
                    CausesValidation="True"
                    runat="server"/>
 
Leave a comment

Posted by on September 21, 2010 in ASP.Net Validation

 

Display Date Formate and User Name with Login Control


if you want to display date in this formate then use this code

lblDate.Text = DateTime.Now.ToString(“ddd”) + ‘ ‘ + DateTime.Now.Day.ToString() + ‘ ‘ + DateTime.Now.ToString(“MMMM”) + ‘ ‘ + DateTime.Now.Year.ToString();

you you want to display full day then just

DateTime.Now.ToString(“dddd”)

Login Control

write this code at master page.

if (HttpContext.Current.User.Identity.IsAuthenticated == true)
{

tvLeftNav.Visible = true;
loginImg.Visible = true;
}
else
{
tvLeftNav.Visible = false;
}

For display at Each Page top where user login then this code write at master page

<div>
<asp:loginview ID=”LoginView1″ runat=”server”>
<loggedintemplate>

<asp:loginname id=”LoginName1″ runat=”server” formatstring=”{0}” />

</loggedintemplate>

</asp:LoginView>
</div>

For Logout

<div>
<asp:LoginStatus ID=”LoginStatus2″ runat=”server”
LogoutAction=”RedirectToLoginPage” LogoutPageUrl=”~/login.aspx” LogoutImageUrl=”~/images/12_icon.png” LoginImageUrl=”~/images/12_icon.png” />

</div>

 
Leave a comment

Posted by on September 15, 2010 in ASP Dot Net C#

 

FileUpload Control Use in Wizard Control!


i have problem face when i use File Upload Control in Wizard Control.When i use multiple Step in Wizard control and Fileupload Control use at First Step,When i reach at last step then Submit The Information for Save then FileUpload Control Empty or No File.So,The Image Not Save in Database and in Directory.

after to much  Search on Net but i Can’t Found solution.After deeply workout then i reach to find the solution.

Solution:

At First Next Step you write the File Upload Code Like

string _ImgName = string.Empty;

//Set Directory Path in Web.config Fiel ,just change Folder Name from  WebConfig
string folderPath = ConfigurationManager.AppSettings.Get(“ImagePath”);

string ImgPathimg = Request.PhysicalApplicationPath + folderPath;
fuPicture.EnableViewState = true;
if (fuPicture != null && fuPicture.HasFile)
{

_ImgName = System.IO.Path.GetFileName(fuPicture.PostedFile.FileName);

// This is use for  Unique Path for every document
string name = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + “_”;

string _imgrnd = name + _ImgName;
ImgPathimg = ImgPathimg + _imgrnd;
string name1 = _imgrnd;
ViewState[“ImagePath”] = ImgPathimg;
//  fuPicture.SaveAs(ImgPathimg);
// reg.PicturePath = _imgrnd;
ViewState[“ImageName”] = _imgrnd;
}

WizaApplyOnline.ActiveStepIndex = 1;

————————————————–

Save Image Path in View State

ViewState[“ImagePath”] = ImgPathimg;

Save Image Name

ViewState[“ImageName”] = _imgrnd;

After  Going Next Step

———————-

————————–

Last Step write this Code……….

if (ViewState[“ImageName”] != null && ViewState[“ImageName”] != string.Empty)
{
fuPicture.SaveAs(ViewState[“ImagePath”].ToString());
//   reg.PicturePath = _imgrnd;
reg.PicturePath = ViewState[“ImageName”].ToString();

}
else {
reg.PicturePath = “”;

}

your Problem resolve


 
1 Comment

Posted by on September 7, 2010 in ASP Dot Net C#