Archive

Archive for August, 2009

Textbox Watermark using Ajaxtoolkit or By Javascript

August 31, 2009 2 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);”);
Advertisements

Disable button after submit in Asp.net

August 28, 2009 Leave a comment

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

Preview/Show Uploaded Image in Asp.net

August 26, 2009 Leave a comment

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

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

August 25, 2009 3 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.

Changing Css Class or Style At Run time dynamically in Asp

August 21, 2009 Leave a comment

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

Lets say you have:

<a ID=”linktemp” style=”text-decoration:underline” class=”verdana12bluebold” runat=”server” >Download</a>

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”);

How to Get Table Structure Using SQL Query

August 20, 2009 Leave a comment

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…