Monday, October 18, 2010

Sql - server - Find Last updated stored procedures

SELECT name, create_date, modify_date
FROM sys.objects
WHERE type = 'P'
ORDER BY modify_date desc, create_date desc

Wednesday, October 6, 2010

SQL-Server - Generalized Paging Query That Includes Sorting Clauses

SELECT TOP page_size * FROM table WHERE primary_key NOT IN
(SELECT TOP page_size * (page_number - 1) primary_key FROM table
WHERE filter_conditions
ORDER BY sort_field)
AND filter_criteria
ORDER BY sort_field

How do I open PDF's to specific pages?

Open a PDF to a specific page from a web-server
1. Use name/destination pairs when you Distill your PDF document. Please refer to the https://partners.adobe.com/asn/acrobat/sdk/explodedSDK/Documentation/PDF_Creation_APIs/pdfmarkReference.pdf This is designed for PostScript engineers or for those who are generating their own PostScript.
2. Use a highlight file.
3. append #page=x [where x is the page number].
4. Select File > Document Properties > Open Options and target the page and view you want. This is the easiest, but least flexible method, as you get exactly one view that you can open to.

JavaScript function to check/Uncheck all the check boxes on a form

function CheckAll(flag) {
var fmobj = document.friendbox;
for (var i=0;i {
var e = fmobj.elements[i];
if(e.type=='checkbox')
{
if(flag=='false')
e.checked = false;
else
e.checked = true;
}
}
}

javascript to get values of query string variable:

var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}

Javascript: Function to get Cookies values

function getCookiesValue(objCkNm)
{
var beginindex, endindex, result, num;
num = objCkNm.length;
beginindex=document.cookie.indexOf(objCkNm) + num +1 ;
endindex=beginindex;
//while we haven't hit ";" and it's not end of cookie
while (document.cookie.charAt(endindex)!=";" && endindex <= document.cookie.length)
endindex++

//result contains "JavaScript Kit"
result=document.cookie.substring(beginindex,endindex)
return result;
}

Javascript: function to check that number is numeric

function IsNumeric(strString)
{
// check for valid numeric strings
var strValidChars = "0123456789.-";
var strChar;
var blnResult = true;

if (strString.length == 0) return false;

// test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
blnResult = false;
}
}
return blnResult;
}

Javascript: Email Validation function

function ValidateEmail(str)
{
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1)
{
alert("The eMail address '@' convention appears to be invalid.")
return false
}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
{
alert("The eMail address '@' convention appears to be invalid.")
return false
}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("The eMail address 'dot' convention appears to be invalid.")
return false
}

if (str.indexOf(at,(lat+1))!=-1)
{
alert("The eMail address '@' convention appears to be invalid.")
return false
}

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
{
alert("The eMail address 'dot' convention appears to be invalid.")
return false
}

if (str.indexOf(dot,(lat+2))==-1)
{
alert("The eMail address 'dot' convention appears to be invalid.")
return false
}

if (str.indexOf(" ")!=-1)
{
alert("The eMail address spacing convention appears to be invalid.")
return false
}
return true
}

Javascirpt : . function to Remove spaces

function removeSpaces(string) {
var tstring = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
tstring += splitstring[i];
return tstring;
}

This function used with the onclick event of File Html Control, this shows the image when You click on the / File Html Control or “Browse” image

function DoPreview()
{
var filename = document.form1.filesent.value;
var Img = new Image();
if (navigator.appName == "Netscape")
{
alert("Previews do not work in Netscape.");
}
else
{
Img.src = filename;
document.images[0].src = Img.src;
}
}

How to register dot net framework

  1. Download the framework from the Microsoft
  2.  install the framework from the executable site
  3. registration
    1. Open the Command Prompt
    2. Go to the path where Framework installed
    3. Execute the command "aspnet_regiis -i" to register the .Net framework

DataGrid Export to excel file

private void ExportGridToExcel(DataGrid grdGridView, string fileName)
{
Response.Clear();
Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xls", fileName));
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
grdGridView.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}

Read a File

1. Map The Server Path
string strFileName = Server.MapPath("partnership_msg.txt");

2. Here is the code to Read Text File From Path "partnership_msg.txt" into streamReader
StreamReader sr = new StreamReader(new FileStream(strFileName,FileMode.Open, FileAccess.Read));

3. Read the content from the StreamReader into string variable
strBody = sr.ReadToEnd();

4. Close the Streamreader
sr.Close();

how to resize image and show resized image

step 1: Take a image button and assign ImageUrl is equal to original Image Path
Eg :- Image.ImageUrl = "image/originalImage.jpeg"

Step 2: Then On pageLoad write the code:-
Image.ImageUrl = "view.aspx?imgUrl =" + Image.ImageUrl + "&Width=100&Height=100";

step 3: write the Following Coding on the view.aspx Page:-


private void Page_Load(object sender, System.EventArgs e)
{
string url="../Products/image/imageNot.jpg";
int Weight=60,Height=60;
if(Request.QueryString["URL"]!=null)
{
url = Request.QueryString["URL"].ToString();
Weight = Convert.ToInt32(Request.QueryString["Width"].ToString());
Height = Convert.ToInt32(Request.QueryString["Height"].ToString());
}
Resize(url,Weight,Height);
}

public void Resize(string strPath, int Weight, int Height)
{
string strFile = strPath.Substring(strPath.LastIndexOf("/")+1);
string urlPhysical = HttpContext.Current.Server.MapPath(strPath);
if(!File.Exists(urlPhysical))
{
urlPhysical = HttpContext.Current.Server.MapPath("../images/imageNot.jpg");
}
Bitmap btm = ResizeImage(urlPhysical,Weight,Height);
ImageConverter ic = new ImageConverter();
byte[] btImage1 = new byte[1];
btImage1 = (byte[])ic.ConvertTo(btm, btImage1.GetType());
Response.BinaryWrite(btImage1);
}

public Bitmap ResizeImage(string url, int intH,int intW)
{
Bitmap objImg = new Bitmap(url);
Bitmap outputImage = new Bitmap(intW, intH, objImg.PixelFormat);
outputImage.SetResolution(objImg.HorizontalResolution, objImg.VerticalResolution);
Graphics graphics = Graphics.FromImage(outputImage);
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.DrawImage(objImg, new Rectangle(0, 0, intW, intH),new Rectangle(4, 4, objImg.Width-4, objImg.Height-4), GraphicsUnit.Pixel);
graphics.Dispose();
return outputImage;
}

How to get the readonly textbox value on the server

In ASP.NET 2.0 and Newer versions , the readonly TextBox will ignore the submitted text , this change due to security reasons .

However , assume you have a readonly textbox and you are going to change its value on the client side ( via script) ,
Now how you will get the changed value on the server side ? One option is to disable the textbox control ,
and set "SubmitDisabledControls" for the form to true , but this is not always a solution .

For example you want to use the Calendar extendar with the textbox and you don't want to let the user to change the textbox manually ,
instead you want to let the user select the date via the calendar extendar. now the problem is that the selected date will not be
accepted by the textbox when the user submit the form , because the textbox is in readonly mode ,
in this case you need to manually set the submitted textbox value , you can easily use the values that is submitted via form collection ,

something like this:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.Text = Server.HtmlEncode(Request.Form(TextBox1.UniqueID))
End Sub

There is also many solutions other than setting the textbox as readonly ,
for example you can cancel the onCopy,onPaste,onkeyup all the required javascript events .

Generate a random number:

1. Generate a random number:
Random rnd = new Random();
intRandomNumber = rnd.Next();
rnd =null;

2. Generate a random number between a range(1 to 4)
Random rnd = new Random();
intRandomNumber = rnd.Next(1,5);
rnd =null;

UserControls

User Control: User Control is the custom, reusable controls. User Controls offers a way to partition and reuse User Interface (UI) functionality across ASP.NET Applications.
Advantages of User Control:
• Code Reuse.
• Cache the output of the control independently using technique called fragment caching. This will improve performance if used appropriately.
• Can program against any properties declared in the control, just like ASP.NET web controls.

Disadvantages of User Control:
• User Controls can be instantiated in the pages that resides in the same web application. If you want to use across applications, you need to place same .ascx control in each application.
• Can't hide code of user controls like server controls by compiling into an assembly.

Adding User Controls to an WebForms Page:
At the top of the .aspx page, add the below line above tag.
<!--Register TagPrefix="Test" TagName="TestControl" Src="Test.ascx"-->
This directive registers the control so that it can be recognized when the page is processed. TagPrefix determines the unique namespace of the control, TagName is the name of the user control and Src is the path of the user control.

If your user control is registered into Web.Config then there is no need to register on each page.
Declare user controls like
<testcontrol id="TestControl" runat="Server">>

Accessing and Setting User Controls Values in the .aspx Page:
User can access and set the values of the User Control from .aspx page through properties, using JavaScript and in code-behind of aspx page. The details of it are shown below
1. Using Properties:If the test.ascx control has two textboxes and submit button. You can access the values of the textboxes in the control from an .aspx page by declaring public property in the .ascx page.
Public Property FirstName() As String
Get
    Return txtFirstName.Text
End Get
Set
   txtFirstName.Text = Value
End Set
End Property
In .aspx page,you can access FirstName using "TestControl.FirstName" & You can set the FirstName of the control from aspx page using TestControl.FirstName = "Suzzanne"

2. Using Javascript: You can set the values of the controls declared in the .ascx page by
Private document.forms(0)("TestControl:txtFirstName").value ="Suzzanne"
You can get the values of the controls declared in the .ascx page by
Private document.forms(0)("TestControl:txtFirstName").value

3. In ASPX code behind file:
Private objTestControl As TestControl = CType(Page.FindControl("TestControl"), TestControl)
Private objTextBox As TextBox = objTestControl.FindControl("txtFirstName")Private strFirstName As String = objTextBox.Text

Add a Scrollbar(with defined color)

.ScrollBar
{
overflow: auto;
height: 100%;
scrollbar-face-color: #c7c57b;
scrollbar-highlight-color: #c7c57b;
scrollbar-3dlight-color: #c7c5Db;
scrollbar-darkshadow-color: #c7c57b;
scrollbar-shadow-color: #00000;
scrollbar-arrow-color: #000000;
scrollbar-track-color: #F9F9DF;
}

Tuesday, October 5, 2010

AutoCompleteType = "Disabled" for textbox is not working in firefox.

Use autocomplete="off"  instead of  AutoCompleteType = "Disabled".

AutoCompleteType = "Disabled" - not works in all browsers

autocomplete="off" -  works in all browsers