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......

Tuesday, August 25, 2009

Getting Last Modified/Created Table, Stored Procedure, Function.. in Sql Server

· 1 comments

Sometimes, we want to know how many tables, stored procedures or functions we have created on a particular day, or on which tables, sps or functions, modifications have occured. All this can be known through a very simple sql query, which is as below:

select name,type,type_desc, create_date, modify_date from sys.objects

where convert(varchar,modify_date,101) = convert(varchar,getdate(),101)

order by modify_date desc

Here

name : - "Its the table or sp or function name"

type: - "To identify a table or sp or function etc.. P, S, U"

type_desc: -"Description whether it is table, sp etc.."

- S = System Table, PK = Primary Key,U = User Table,

- P= Stored Procedure, TF = Table Value Function,

- FN = Scalar Function, D= Default Constraint

create_date: - "Date when it is created"

modify_date: - "Last modified datetime of table, sp,.. etc"

In above query, in place of getdate(), you can pass the date you want, also you can get complete list after removing where condition, just giving order by modified date from sys objects..

Very important when we want to generate scripts for particular tables, sps or function for a particular date.

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

How to Get Table Structure Using SQL Query

· 0 comments

Sql life made so easy..

See how..

View/Copy, structure of table in sql in just one line query….

select * from tablename where 1<>1

cheers…

Read More......

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......