Saturday, March 28, 2009

Calendar Using JavaScript with MastePage

Many people using master page might wonder why calendar control is not opening if they are using master page in their normal aspx page., If you add and call the JavaScript cleaner control similar to the normal aspx page calendar won’t be displayed in the page using master page….so I just posting this article to show you how this works….
There is no extra or special coding for this…
First, add JavaScript/CSS reference in MASTER page like below,
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head runat="server">
    <title>Maste Page</title>
    <script src="\calendar\calendar.js" type="text/javascript"></script>
    <link href="\calendar\Calendar.css" rel="stylesheet" type="text/css" />
    <form id="form1" runat="server">
        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
Then call the JavaScript function to show the calendar based on the JavaScript you are using. Here my function is
showCalendar(<TextBox Name>,<Date Format>)
instead of passing control name we are passing ID of the control. This is the only change you have to remember…
<asp:TextBox ID="txtDateCreated" runat="server"></asp:TextBox><input id="DateCreated" onclick="return showCalendar('ctl00_ContentPlaceHolder1_txtDateCreated', '%m/%d/%Y',true);" type="image" src="calendar/calendar.gif">
Execute the code…see that wonderful calendar.

Monday, March 23, 2009

How to return values from JavaScript function to the C# page load

Add the JavaScript function just below the HTML <title> tag. This function should have __doPostBack to return value.
   1:     <script language="javascript">
   2:          function RetVal()
   3:          {
   4:              var testVar = 'abc'
   5:              __doPostBack('Test',testVar);
   6:          }
   7:      </script>

Add a label to display the values from JavaScript function.
Add a text box to page and set the AutoPostBack property to true. One control with AutoPostBack property set to true is required in the page to get the value from JavaScript function using __doPostBack.
In Page_Load write the following code.
   1:  protected void Page_Load(object sender, EventArgs e)
   2:  {
   3:    if (IsPostBack)
   4:    {
   5:      string arg = Request.Form["__EVENTTARGET"];
   6:      string val = Request.Form["__EVENTARGUMENT"];
   7:      if (arg == "Test")
   8:      {
   9:       Label1.Text = val;
  10:      }
  11:    }
  12:     else
  13:     {
  14:      string script;
  15:      script = @"<SCRIPT language='javascript'> RetVal
           ();" + "</SCRIPT>";
  16:      Page.RegisterStartupScript("Test", script);
  17:     }
  18:    }

Page.RegisterStartupScript: Allows ASP.NET server controls to emit client-side script blocks in the Page, now this method is obsolete, in ASP.NET 2.0 it gives you an error - or more correctly warnings telling you that both functions are obsolete.
'System.Web.UI.Page.IsStartupScriptRegistered(string)' is obsolete: 'The recommended alternative is ClientScript.IsStartupScriptRegistered(string key).
"The __EVENTTARGET hidden variable will tell the server ,which control actually does the server side event firing so that the framework can fire the server side event for that control."
The __ EVENTARGUMENT variable is used to provide additional event information if needed by the application, which can be accessed in the server
Execute the code and see the result…

Tuesday, March 3, 2009

List all the Stored Procedures Associated with a specific Table

SET @TABLENAME='<table name>'    --Pass the Table Name here
SELECT @TableName as [Table Name],A.Name AS [SP Name],B.Text as [SP Text] from SYSOBJECTS A
WHERE B.TEXT LIKE '%'+@TableName+'%'
and A.TYPE='P'
Same way we can use this to find out View, Trigger etc..
V: View
TR: Trigger

See the out put…

SQL query to fetch all the tables and column names from the database

select table_name, column_name, data_type, character_maximum_length, is_nullable 
from information_schema.columns 
where table_name in (select name from sysobjects where xtype='U') order by table_name

Here xtype='U' means user table.

Some of the other options you can use are,
C: Check constraint
D: Default constraint
F: Foreign Key constraint
L: Log
P: Stored procedure
PK: Primary Key constraint
RF: Replication Filter stored procedure
S: System table
TR: Trigger
U: User table
UQ: Unique constraint
V: View
X: Extended stored procedure
Press F5 and see the result!!!!!!