Opening a page from javascript

function ok_click() {
        if ($get('<%=txtRowsPage.ClientID%>').value != '') {
            window.location.href = window.document.URL + '?rpp=1&rows=' + $get('<%=txtRowsPage.ClientID%>').value;
        }
    }

Focussing the curser to a field

Sys.Application.add_load(function() {
        var popup = $find('mpeRowsPage');
        popup.add_shown(function() {
            $get('<%= txtRowsPage.ClientID %>').focus();
        });
    });

Dataset Value retrival

string u_login = "", u_email = "", u_id = "", u_fname = "", u_lname = "";
DataView dv1 = ds1.Tables[0].DefaultView;
dv1.RowFilter = "user_id=" + id;
DataTable dt1 = dv1.ToTable();
u_login = dt1.Rows[0]["user_login"].ToString();
u_email = dt1.Rows[0]["user_email"].ToString();
u_id = dt1.Rows[0]["user_id"].ToString();
u_fname = dt1.Rows[0]["user_first_name"].ToString();
u_lname = dt1.Rows[0]["user_last_name"].ToString();

mailto

HTML mailto attribute - HTML tips

The mailto is a quick way to add the facility of receiving feedback from visitor on your web site. With the HTML mailto, you create a link which when clicked by the visitor launches (if it's not already running) their email program with a new email message window. The visitor could then formulate the email message and send it off to you.
Note: HTML Mailto assumes that the visitor has configured an email client (Outlook Express, Netscape Messenger, Thunderbird or any other) to send emails.
In its simplest form, the HTML mailto requires an email address. However, mailto can be made slightly more professional if we use it properly.

The Basic form of HTML mailto

In its bare form a mailto looks like:
<a href="mailto:manish@simplygraphix.com">Send me an 
email</a>
And this is displayed as
Send me an email
When you click on the above link, your default email client will be launched (if you've configured one). You'll notice that the Subject and Body fields of the email message are empty. [Refer image below: I use Outlook Express email client and the snapshot below is from that program.]
The basic form of the HTML mailto

A more complex HTML mailto

We will now learn how to create a more complex HTML mailto by adding an email subject and the email body so that it looks a little more professional. And this will definitely save your visitors some typing too!
<a href="mailto:manish@simplygraphix.com?subject=Feedback for 
webdevelopersnotes.com&body=The Tips and Tricks section is 
great">Send me an email</a>
Send me an email
When you click on the above link, the Email Subject and the Email Body fields will be prefilled to "Feedback for webdevelopersnotes.com" and "The Tips and Tricks section is great" values, respectively. [Refer image below: Again, it's a snapshot from Outlook Express email client.]
A more complex form of the HTML mailto attribute carrying the email subject and and email body

Careful inspection of the above code will highlight two points. Firstly, the email address is separated from the other information by a ? sign (question mark) and secondly, body and subject properties are themselves separated using an &.
[Those of you familiar with server-side scripting will find a similarity between this mailto tag and the GET method.]
Remember, the prefilled email Subject and email body values can be changed by the visitor! But this fancy mailto looks better than plain one, doesn't it?
In addition to the body and subject, we can also provide HTML mailto with CC (Carbon Copy) and BCC (Blind Carbon Copy). This, as you would have guessed, requires us to append these values to the HTML mailto attribute just like we had done for body and subject. [Refer code and image below]
<a href="mailto:manish@simplygraphix.com?subject=Feedback for 
webdevelopersnotes.com&body=The Tips and Tricks section is great
&cc=anotheremailaddress@anotherdomain.com
&bcc=onemore@anotherdomain.com">Send me an email</a>
Send me an email
new email message created using HTML mailto with the body, subject, cc and bcc all prefilled

Advantages of HTML mailto attribute

HTML mailto is a quick and easy way for beginners or who don't know server-side programming languages (such as Perl, PHP etc.) to add a link on their web site for receiving visitor feedback. By the way, you can be more intuitive with HTML mailto. For example, you can use it to create "Tell a friend" or "Send this page to a friend" kind of links on your web site. For your convenience, here is the code and the link.
<a href="mailto:?subject=Check out www.webdevelopersnotes.com
&body=Hi, check out this great web site">
Send this page to a friend</a>
Send this page to a friend
You will notice that we have left out the email address so that the visitor can enter any email address they want but the question mark remains.

Share url in twitter

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css" media="screen">
  #custom-tweet-button a {
    display: block;
    padding: 2px 5px 2px 20px;
    background: url('http://a4.twimg.com/images/favicon.ico') 1px center no-repeat;
    border: 1px solid #ccc;
  }
</style>
</head>

<body>

<%
 dim Thispage="http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL") & "?" & Request.Querystring
%>

        <iframe id="sm_tweet" name="sm_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=<%=Thispage%>" allowTransparency="true" frameborder="0" scrolling="no" style="width:100px; height:22px;"></iframe>


or

<a href="http://twitter.com/home?status=<%=Thispage%>"; title="Click to share this post on Twitter">Share on Twitter</a>


</body>
</html>

Share the current url in facebook.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css" media="screen">
  #custom-tweet-button a {
    display: block;
    padding: 2px 5px 2px 20px;
    background: url('http://a4.twimg.com/images/favicon.ico') 1px center no-repeat;
    border: 1px solid #ccc;
  }
</style>
</head>

<body>


<script>function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'toolbar=0,status=0,width=626,height=436');return false;}</script><style> html .fb_share_button { display:marker; padding:1px 20px 0 5px; height:20px; border:1px solid #d8dfea; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; font-weight:500; background:url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26983) no-repeat center  right; } html .fb_share_button:hover { color:#fff; border-color:#295582; background:#3b5998 url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat  right; text-decoration:none; } </style> <a rel="nofollow" href="http://www.facebook.com/share.php?u=http://thewesternvault.com/listings/listing_detail.asp?listing_ID=3133" class="fb_share_button" onclick="return fbs_click()" shape="round" target="_blank" style="text-decoration:none;">Share</a>
</body>
</html>

Java Script History object

The History object contains an array of previously visited URLs by the visitor. To simulate the browser's back button, for example, you can use the History object:

<a href="javascript:history.go(-1)">Go back</a>


Properties

Properties Description
length Returns the number of URLs in the browser's history list.

Methods

Methods Description
back() Loads the previous URL in the history list.
forward() Loads the next URL in the history list.
go(whereTo) Goes to a specific URL within the history list. "whereTo" can be an integer to go to a URL within a specific position relative to the current (ie: -1 goes back one page, 1 goes forward one), or a string. For the string, enter a partial or full URL, and the function to match and go to the first URL that matches the string. Example(s).

Examples

 go(whereTo)

<a href="javascript:history.go(-3)">Go back 3 pages</a>
<a href="javascript:history.go('javascriptkit.com')">Go to nearest URL in history list with "javascriptkit.com" in the URL.</a>

 

How to call a javascript function through the radio button click. with parameter passing

Java script
----------------------------------------------------------------------------------------------------------

 function SelfRegd(state)
      {
      if(state =="Yes")
      document.getElementById('<%=pnlSelfRegd.ClientID%>').style.display='inline';
      else if(state=="No")
      document.getElementById('<%=pnlSelfRegd.ClientID%>').style.display='none';
      }

Aspx
------------------------------------------------------------------------------------------------------------

<asp:RadioButton ID="rbtSelfRegtYes" onclick="return  SelfRegd('Yes');" runat="server" Text="Yes" GroupName="SelfRegt" />
                                    <asp:RadioButton ID="rbtSelfRegtNo" onclick="return  SelfRegd('No');" runat="server" Text="No" GroupName="SelfRegt" />


--------------------------------------------------------------------------------------------------------
OR
from code behind

pageload
---------------------------------------------------------------------------------------------------------

rbtSelfRegtYes.Attribute.Add("onclick","return SelfRegd('Yes')");


How to call a java script function by fire dropdownlist on selectedindex change event

from the pageload
-------------------------------------------------------------------------------------------------------------
 dropdownList.Attributes.Add("onChange", "return OnSelectedIndexChange();");

Inside javascript
--------------------------------------------------------------------------------------------------------------
   function OnSelectedIndexChange()
     {
         
      }

How to do change style in onmouseover and onmouseout from the code behind

pnlAdded.Attributes.Add("onmouseover", "javascript:this.style.backgroundColor = 'Yellow';this.style.color = 'Black';");
               pnlAdded.Attributes.Add("onmouseout", "javascript:this.style.backgroundColor = 'Red';this.style.color = 'White';");


 lnk.Attributes.Add("onmouseover", "this.style.textDecoration='none';this.style.fontWeight='bold';")
                    'lnk.Attributes.Add("onmouseover", "this.style.textDecoration='none'")
                    lnk.Attributes.Add("onmouseout", "this.style.fontWeight='normal';")
pnlAdded is id for the panel .
lnk is id for linkbutton

How to access and change the html controls background color.

 HtmlTableRow thTopPanel = (HtmlTableRow)e.Item.FindControl("thTopPanel");
                thTopPanel.Style.Add(HtmlTextWriterStyle.BackgroundColor, "Green");

How to access the html controls from the code behind

HtmlTableRow thTopPanel = (HtmlTableRow)e.Item.FindControl("thTopPanel");

thTopPanel->id of the th of the table.

HtmlTableCell htc = (HtmlTableCell)e.Item.FindControl("dateLtlContainer"); 


dateLtlContainer->id for td of the table.

Repeater controls

<asp:Repeater ID="dayRepeater" runat="server"  OnItemDataBound="dayRepeaterItemDataBound">
                <HeaderTemplate>
                <%--PKM added id for the tr--%>
                    <table class="main" cellspacing="0" cellpadding="0" align="center">
                        <tr id="thTopPanel" runat="server">
                            <th   class="empty" style="height: 29px;">
                                &nbsp;
                            </th>
                            <th id="dateLtlContainer" runat="server" style="height: 29px; width: 560px">
                                <asp:Literal ID="dateLtl" runat="server" />
                            </th>
                        </tr>
                       
                </HeaderTemplate>
                <ItemTemplate>
                    <tr id="apptRow" runat="server">
                     <%--PKM added id for the th--%>
                        <th class="row" id="thLeftPanel" runat="server" width="10px">
                            <asp:Literal ID="timeLtl" runat="server" />
                        </th>
                        <td>
                            <div style="text-align: right;">
                                <a id="cal_dayadd_event" href="events.aspx" runat="server">
                                    <img alt="" border="0" src="images/icon-add-big.gif" />
                                </a>
                            </div>
                            <asp:Repeater ID="dayChildRep" runat="server" OnItemDataBound="dayChildRep_ItemDataBound">
                                <ItemTemplate>
                                    <div style="text-align: left;">
                                        <asp:Panel ID="target_panel" runat="server">
                                            <input type="hidden" id="patMrnh" runat="server" />
                                            <input type="hidden" id="patLastNmh" runat="server" />
                                            <input type="hidden" id="patFirstNmh" runat="server" />
                                            <input type="hidden" id="apptDateh" runat="server" />
                                            <input type="hidden" id="apptTimeh" runat="server" />
                                            <input type="hidden" id="apptParticipantsh" runat="server" />
                                            <input type="hidden" id="apptTitleh" runat="server" />
                                            <input type="hidden" id="apptTypeh" runat="server" />
                                            <input type="hidden" id="apptDesch" runat="server" />
                                        </asp:Panel>
                                    </div>
                                </ItemTemplate>
                            </asp:Repeater>
                        </td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>

  protected void dayRepeaterItemCommand(Object sender, RepeaterCommandEventArgs e)
        {

        }



  protected void dayRepeaterItemDataBound(Object Sender, RepeaterItemEventArgs e)
        {
            string times = "";

         
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

                //PKM
                HtmlTableCell thTopPanel = (HtmlTableCell)e.Item.FindControl("thLeftPanel");
                thTopPanel.Style.Add(HtmlTextWriterStyle.BackgroundColor, "Green");
                string str1 = "Red";
                //PKM


                Literal timeCol = (Literal)e.Item.FindControl("timeLtl");
                if (DataBinder.Eval(e.Item.DataItem, "times").ToString() != "")
                {
                    if (DataBinder.Eval(e.Item.DataItem, "times").ToString() != "All Day")
                        timeCol.Text = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "times")).ToShortTimeString();
                    else
                        timeCol.Text = DataBinder.Eval(e.Item.DataItem, "times").ToString();
                }
                times = timeCol.Text;
                //PKM
                timeCol.Text = "<font color='" + str1 + "'>" + times + "</font>";
                //PKM
                HtmlAnchor cal_dayadd_event = (HtmlAnchor)e.Item.FindControl("cal_dayadd_event");
                if (cal_dayadd_event != null)
                    cal_dayadd_event.HRef = "events.aspx?day_date=" + hdnDate.Value + "&day_time=" + times;

                Repeater dayChildRep = (Repeater)e.Item.FindControl("dayChildRep");
                DataSet local_ds = GetApptsByTime(times);
                if (local_ds.Tables.Count > 0)
                {
                    dayChildRep.DataSource = GetApptsByTime(times);
                    dayChildRep.DataBind();
                }
            }

            if (e.Item.ItemType == ListItemType.Header)
            {
                //PKM
                HtmlTableRow thTopPanel = (HtmlTableRow)e.Item.FindControl("thTopPanel");
                thTopPanel.Style.Add(HtmlTextWriterStyle.BackgroundColor, "Green");
                string str = "Red";
                //PKM
              
                Literal dateCol = (Literal)e.Item.FindControl("dateLtl");
               
                if (Request["day"] != null)
                {
                    if (Convert.ToDateTime(Request["day"]).Date != DateTime.Now.Date)
                    {
                        //PKM ADDEDTHE FONT TAG
                        dateCol.Text = "<font color='" + str + "'>" + Convert.ToDateTime(Request["day"]).DayOfWeek.ToString() + Convert.ToDateTime(Request["day"]).ToString("<br />MMMM d, yyyy") + "</font>";
                    }
                    else
                    {
                        //PKM ADDEDTHE FONT TAG
                        dateCol.Text = "<font color='" + str + "'>" + DateTime.Now.DayOfWeek.ToString() + DateTime.Now.ToString("<br />MMMM d, yyyy") + "</font>";
                        HtmlTableCell htc = (HtmlTableCell)e.Item.FindControl("dateLtlContainer");
                        htc.Attributes.Add("class", "today");
                    }
                }
                else
                {
                    //PKM ADDEDTHE FONT TAG and date format
                    string st = "d.MM.yy";
                    dateCol.Text = "<font color='" + str + "'>" + DateTime.Now.DayOfWeek.ToString() + DateTime.Now.ToString("<br />"+st) + "</font>";
                    HtmlTableCell htc = (HtmlTableCell)e.Item.FindControl("dateLtlContainer");
                    htc.Attributes.Add("class", "today");
                }
            }
        }

 protected void dayChildRep_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
        {
            string event_id = "", event_title = "", event_date = "", event_time = "", event_time_end = "",
                event_AppointmentType = "", event_PatLastName = "", event_PatFirstName = "", event_PatMrnNumber = "",
                event_Participants = "", event_is_public = "", event_desc = "", event_all_day = "", event_ParticipantsText = "";

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                event_id = DataBinder.Eval(e.Item.DataItem, "event_id").ToString();

                if (!(DataBinder.Eval(e.Item.DataItem, "event_time").ToString() == string.Empty))
                    event_time = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "event_time")).ToShortTimeString();

                if (!(DataBinder.Eval(e.Item.DataItem, "event_time_end").ToString() == string.Empty))
                    event_time_end = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "event_time_end")).ToShortTimeString();

                if (!(DataBinder.Eval(e.Item.DataItem, "event_Participants").ToString() == string.Empty))
                    event_Participants = DataBinder.Eval(e.Item.DataItem, "event_Participants").ToString();

                if (!(DataBinder.Eval(e.Item.DataItem, "event_ParticipantsText").ToString() == string.Empty))
                    event_ParticipantsText = DataBinder.Eval(e.Item.DataItem, "event_ParticipantsText").ToString();

                if (!(DataBinder.Eval(e.Item.DataItem, "event_all_day").ToString() == string.Empty))
                    event_all_day = DataBinder.Eval(e.Item.DataItem, "event_all_day").ToString();

                if (!(DataBinder.Eval(e.Item.DataItem, "event_desc").ToString() == string.Empty))
                    event_desc = DataBinder.Eval(e.Item.DataItem, "event_desc").ToString();

                if (!(DataBinder.Eval(e.Item.DataItem, "event_is_public").ToString() == string.Empty))
                    event_is_public = DataBinder.Eval(e.Item.DataItem, "event_is_public").ToString();

                if (!(DataBinder.Eval(e.Item.DataItem, "event_AppointmentType").ToString() == string.Empty))
                    event_AppointmentType = DataBinder.Eval(e.Item.DataItem, "event_AppointmentType").ToString();

                if (!(DataBinder.Eval(e.Item.DataItem, "event_title").ToString() == string.Empty))
                    event_title = DataBinder.Eval(e.Item.DataItem, "event_title").ToString();

                if (!(DataBinder.Eval(e.Item.DataItem, "event_PatLastName").ToString() == string.Empty))
                    event_PatLastName = DataBinder.Eval(e.Item.DataItem, "event_PatLastName").ToString();

                if (!(DataBinder.Eval(e.Item.DataItem, "event_PatFirstName").ToString() == string.Empty))
                    event_PatFirstName = DataBinder.Eval(e.Item.DataItem, "event_PatFirstName").ToString();

                if (!(DataBinder.Eval(e.Item.DataItem, "event_PatMrnNumber").ToString() == string.Empty))
                    event_PatMrnNumber = DataBinder.Eval(e.Item.DataItem, "event_PatMrnNumber").ToString();

                if (!(DataBinder.Eval(e.Item.DataItem, "event_date").ToString() == string.Empty))
                    event_date = DataBinder.Eval(e.Item.DataItem, "event_date").ToString();

                Panel target_panel = (Panel)e.Item.FindControl("target_panel");

                HtmlInputHidden patMrnh, patLastNmh, patFirstNmh, apptDateh, apptTimeh, apptParticipantsh, apptTitleh, apptTypeh, apptDesch;
                patMrnh = (HtmlInputHidden)e.Item.FindControl("patMrnh");
                patLastNmh = (HtmlInputHidden)e.Item.FindControl("patLastNmh");
                patFirstNmh = (HtmlInputHidden)e.Item.FindControl("patFirstNmh");
                apptDateh = (HtmlInputHidden)e.Item.FindControl("apptDateh");
                apptTimeh = (HtmlInputHidden)e.Item.FindControl("apptTimeh");
                apptParticipantsh = (HtmlInputHidden)e.Item.FindControl("apptParticipantsh");
                apptTitleh = (HtmlInputHidden)e.Item.FindControl("apptTitleh");
                apptTypeh = (HtmlInputHidden)e.Item.FindControl("apptTypeh");
                apptDesch = (HtmlInputHidden)e.Item.FindControl("apptDesch");

                if (patMrnh != null) patMrnh.Value = event_PatMrnNumber;
                if (patLastNmh != null) patLastNmh.Value = event_PatLastName;
                if (patFirstNmh != null) patFirstNmh.Value = event_PatFirstName;
                if (event_date != "")
                    if (apptDateh != null) apptDateh.Value = Convert.ToDateTime(event_date).ToString("dd-MMM-yy");
                if (event_date != "" && event_time != "" && event_time_end != "")
                { if (apptTimeh != null) apptTimeh.Value = event_time + " - " + event_time_end; }
                else
                { if (apptTimeh != null) apptTimeh.Value = "All Day"; }
                if (apptParticipantsh != null) apptParticipantsh.Value = event_Participants;
                if (apptTitleh != null) apptTitleh.Value = event_title;
                if (apptTypeh != null) apptTypeh.Value = event_AppointmentType;
                if (apptDesch != null) apptDesch.Value = event_desc;

                if (event_Participants != "")
                {
                    Panel pnlAdded = new Panel();
                    pnlAdded.ID = Guid.NewGuid().ToString();

                    Label appLabel = new Label();
                    appLabel.ID = "appLbl" + Guid.NewGuid().ToString();

                    if (event_time == "" && event_time_end == "" && event_date != "")
                        appLabel.Text = "All Day >> <br/>" + event_Participants + "<br/>";
                    else if (event_time != "" && event_time_end != "" && event_date != "")
                        appLabel.Text = event_time + " - " + event_time_end + " >> <br/>" + event_Participants + "<br/>";

                    pnlAdded.Controls.Add(appLabel);
                    target_panel.Controls.Add(pnlAdded);
                    string Red = "Blue";
                    //PKM changed Color of Panel
                    pnlAdded.BackColor = Color.FromName("Red");
                    //PKM
                    pnlAdded.ForeColor = Color.White;
                    pnlAdded.Attributes.Add("onmouseover", "javascript:this.style.backgroundColor = 'Yellow';this.style.color = 'Black';");
                    //PKM CHANGED backgroundColor
                    pnlAdded.Attributes.Add("onmouseout", "javascript:this.style.backgroundColor = '"+Red+"';this.style.color = 'White';");
                    //PKM
                    pnlAdded.Attributes.Add("onclick", "openWin('" + e.Item.ClientID + "','" + event_id + "'); return false");

                    pnlAdded.Controls.Add(new LiteralControl("<hr>"));

                    target_panel.Controls.Add(pnlAdded);

                    #region Dynamically Creating HoverMenuExtender for the Appointment Literals

                    //Creating HoverMenu Panel
                    Panel pnlHover = new Panel();
                    pnlHover.ID = "pnlHover" + Guid.NewGuid().ToString();

                    //Adding Controls to the HoverMenu Panel
                    //Appt Title Label
                    Label lblAppTitle = new Label();
                    lblAppTitle.ID = "AppTitle" + Guid.NewGuid().ToString();
                    lblAppTitle.Font.Bold = true;
                    lblAppTitle.Text = "Appointment&nbsp;Title:";
                    pnlHover.Controls.Add(lblAppTitle);
                    //End
                    pnlHover.Controls.Add(new LiteralControl("<br />&nbsp;&nbsp;"));
                    //ApptTime Value Label
                    Label lblAppTitleVal = new Label();
                    lblAppTitleVal.ID = "AppTitleVal" + Guid.NewGuid().ToString();
                    lblAppTitleVal.Text = event_title;
                    pnlHover.Controls.Add(lblAppTitleVal);
                    //End
                    pnlHover.Controls.Add(new LiteralControl("<br />"));
                    //ApptType Label
                    Label lblAppType = new Label();
                    lblAppType.ID = "AppType" + Guid.NewGuid().ToString();
                    lblAppType.Font.Bold = true;
                    lblAppType.Text = "Appointment&nbsp;Type:";
                    pnlHover.Controls.Add(lblAppType);
                    //End
                    pnlHover.Controls.Add(new LiteralControl("<br />&nbsp;&nbsp;"));
                    //ApptType Value Label
                    Label lblAppTypeVal = new Label();
                    lblAppTypeVal.ID = "AppTypeVal" + Guid.NewGuid().ToString();
                    lblAppTypeVal.Text = event_AppointmentType;
                    pnlHover.Controls.Add(lblAppTypeVal);
                    //End
                    pnlHover.Controls.Add(new LiteralControl("<br />"));
                    //Patient Name Label
                    Label lblPatName = new Label();
                    lblPatName.ID = "PatName" + Guid.NewGuid().ToString();
                    lblPatName.Font.Bold = true;
                    lblPatName.Text = "Patient&nbsp;Name:";
                    pnlHover.Controls.Add(lblPatName);
                    //End
                    pnlHover.Controls.Add(new LiteralControl("<br />&nbsp;&nbsp;"));
                    //Patient Name Value Label
                    Label lblPatNameVal = new Label();
                    lblPatNameVal.ID = "PatNameVal" + Guid.NewGuid().ToString();
                    lblPatNameVal.Text = event_PatLastName + " " + event_PatFirstName;
                    pnlHover.Controls.Add(lblPatNameVal);
                    //End
                    pnlHover.Controls.Add(new LiteralControl("<br />"));
                    //ApptDesc Label
                    Label lblAppDesc = new Label();
                    lblAppDesc.ID = "AppDesc" + Guid.NewGuid().ToString();
                    lblAppDesc.Font.Bold = true;
                    lblAppDesc.Text = "Description:";
                    pnlHover.Controls.Add(lblAppDesc);
                    //End
                    pnlHover.Controls.Add(new LiteralControl("<br />&nbsp;&nbsp;"));
                    //ApptDesc Value Label
                    Label lblAppDescVal = new Label();
                    lblAppDescVal.ID = "AppDescVal" + Guid.NewGuid().ToString();
                    lblAppDescVal.Text = event_desc;
                    pnlHover.Controls.Add(lblAppDescVal);
                    //End
                    pnlHover.Controls.Add(new LiteralControl("<br />"));
                    //ApptParticipants Label
                    Label lblAppParticipants = new Label();
                    lblAppParticipants.ID = "AppParticipants" + Guid.NewGuid().ToString();
                    lblAppParticipants.Font.Bold = true;
                    lblAppParticipants.Text = "Participants:";
                    pnlHover.Controls.Add(lblAppParticipants);
                    //End
                    pnlHover.Controls.Add(new LiteralControl("<br />&nbsp;&nbsp;"));
                    //ApptParticipants Value Label
                    Label lblAppParticipantsVal = new Label();
                    lblAppParticipantsVal.ID = "AppParticipantsVal" + Guid.NewGuid().ToString();
                    if (event_ParticipantsText.Contains(","))
                    {
                        foreach (string names in event_ParticipantsText.Split(",".ToCharArray()))
                        {
                            lblAppParticipantsVal.Text += names + "<br />&nbsp;&nbsp;";
                        }
                    }
                    else
                    {
                        lblAppParticipantsVal.Text = event_ParticipantsText + "<br />";
                    }
                    pnlHover.Controls.Add(lblAppParticipantsVal);
                    //End
                    //pnlHover.Controls.Add(new LiteralControl("<br />"));
                    //Adding controls to Panel End
                    target_panel.Controls.Add(pnlHover);
                    pnlHover.CssClass = "popupMenu";

                    AjaxControlToolkit.HoverMenuExtender hm1 = new AjaxControlToolkit.HoverMenuExtender();
                    hm1.ID = "hm" + Guid.NewGuid().ToString();
                    hm1.TargetControlID = pnlAdded.ID;
                    hm1.PopupControlID = pnlHover.ID;
                    hm1.PopupPosition = AjaxControlToolkit.HoverMenuPopupPosition.Bottom;
                    hm1.PopDelay = 50;
                    hm1.OffsetX = 0;
                    hm1.OffsetY = 0;
                    hm1.HoverDelay = 5;
                    pnlHover.Controls.Add(hm1);

                    #endregion
                }
            }
        }


INSERT TABLE OF CONTENT OF ONE TABLE OF ONE DATABASE INTO ANOTHER TABLE OF ANOTHER DATABASE WHERE THE DESTINATION TABLE WILL BE AUTOMATICALLY CREATED

SELECT * INTO (DESTINATION) DATABASENAME.SCHEMANAME.TABLENAME FROM (SOURCE) DATABASENAME.SCHEMANAME.TABLENAME

EXAMPLE-SELECT * INTO EMP1.DBO.EMPLOYEE FROM EMP2.DBO.EMPLOYEE

INSERT TABLE OF CONTENT OF ONE TABLE OF ONE DATABASE INTO ANOTHER TABLE OF ANOTHER DATABASE

INSERT INTO (DESTINATION) DATABASENAME.SCHEMANAME.TABLENAME FROM  SELECT * FROM (SOURCE) DATABASENAME.SCHEMANAME.TABLENAME

 EXAMPLE ->INSERT INTO EMP1.DBO.EMPLOYEE FROM SELECT * FROM  EMP2.DBO.EMPLOYEE

To make an asp control visible true and false through javascript with out page refresh

 <asp:Panel style="display:none;" ID="pnlFileAttachment" runat="server">
          <table>  <tr>  <td>    ANY CONTENT </td>  </tr>   </table>
    </asp:Panel>
HERE IF IN PLACE OF style="display:none;" WE WILL GIVE VISIBILITY =FALSE THEN WE CAN NOT ACCESS THIS PANEL CONTROL FROM THE JAVASCRIPT BECAUSE WHEN WE MAKE A CONTROL DISPLAY NONE ITS NOT RENDER INTO THE PAGE ,SO WE WILL GET THE OBJECT NOT FOUND EXCEPTION IN THE JAVA SCRIPT
   <td>    <asp:RadioButton ID="rbtFileAttachmentYes" onclick="return  AttachmentPanel('Yes');" runat="server" Text="Yes" GroupName="FileAttachment" />
     <asp:RadioButton ID="rbtFileAttachmentNo" onclick="return AttachmentPanel('No');" runat="server" Text="No" GroupName="FileAttachment"  />
 </td>
 <script language="javascript" type="text/javascript">    function AttachmentPanel(state)
    {
   if(state =="Yes")
    document.getElementById('<%=pnlFileAttachment.ClientID%>').style.display='inline';
    else if(state =="No")
     document.getElementById('<%=pnlFileAttachment.ClientID%>').style.display='none';
    }
</script>
 IN THE PAGE LOAD
-----------------------------------------------------------------------------------------------
   if (ds.Tables[0].Rows[0]["AllowCommentsToEvents"].ToString() == "Yes")   
       {
                rbtCommentToEventYes.Checked = true;
                pnlCommentToEvent.Style.Add(HtmlTextWriterStyle.Display, "inline");
            }            else if (ds.Tables[0].Rows[0]["AllowCommentsToEvents"].ToString() == "No")
            {
                rbtCommentToEventNo.Checked = true;
                pnlCommentToEvent.Style.Add(HtmlTextWriterStyle.Display, "none");
            }
 IF WE NEED TO CHANGE THE VISIBILITY IF ANY CONTROLS FROM JAVA SCRIPT WE HAVE TO USE THIS PROCEDURE .
WHEN RADIO BUTTON YES WILL BE CHECKED THE PANEL  WILL BE DISPLAYED AND WHEN THE RADIO BUTTON NO WILL BE CHECKED THE PANEL WILL NOT BE DISPLAYED.

get the 1st day of the month

 var date=new Date();
         date.setDate(1);
         var strDate=date.toUTCString();
         var firstday=strDate.substring(0,3);

get the last day of a month in a year

 function daysInMonth(month,year)
    {
        month =month +1;
        var lastDate=0;
        var m = [31,28,31,30,31,30,31,31,30,31,30,31];
      if((month)!=2)
     {
           lastDate=m[month-1];
      }
    else if(year%4 != 0)
    {
         lastDate= m[1];
     }
else if(year%100 == 0 && year%400 != 0)
{
    lastDate= m[1];
}
else
lastDate= m[1]+1;

         var date=new Date();
         date.setDate(lastDate);
         var strDate=date.toUTCString();
          var day=strDate.substring(0,3);
         }

How to retrive the value in javascript and set table values


SET HTML LABLE TEXT VALUE
----------------------------------------------------------------------------------------------------------------------
document .getElementById ("label id").innerHTML

SET BACKGROUND COLOT OF <TD>
----------------------------------------------------------------------------------------------------------------------
 document.getElementById(val).style.backgroundColor="#"+document.getElementById('<%=txtCell.ClientID%>').value

SET<TD> TEXT
----------------------------------------------------------------------------------------------------------------------

 document.getElementById("tdHeader").style.color=  "#"+document.getElementById('<%= txtDocTitle.ClientID%>').value;



GETTING VALUE FROM SERVER SIDE TEXTBOX CONTROL

----------------------------------------------------------------------------------------------------------------------
document.getElementById('<%=txtCell.ClientID%>').value

SET HTML LABEL TEXT COLOR
----------------------------------------------------------------------------------------------------------------------

document.getElementById("lbl33").style.color="#"+document.getElementById('<%=txtCell.ClientID%>').value

SET THE TABLE GRID AND THE TEXT COLOR
----------------------------------------------------------------------------------------------------------------------

document.getElementById("tabCalender").style.color=  "#"+document.getElementById('<%= txtTableGridColor.ClientID%>').value;

GET THE SERVER SIDE DROPDOWN LIST CONTROL VALUE
----------------------------------------------------------------------------------------------------------------------
document.getElementById('<%=drpWeekStart.ClientID%>').value

SET TABLE BACKGROUND COLOR
----------------------------------------------------------------------------------------------------------------------
 document.getElementById("tableMain").style.backgroundColor= "#"+document.getElementById('<%= txtTableGridColor.ClientID%>').value;


Get the total structure of a table

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'Tablename'

Maximum id of a table

select max(columnname) from tablename;

No of rows of a table

select count(*) from table name

Find the default values of the columns and the column names


(SELECT column_name,column_default
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'table name')

Find the no of column of a table.


SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'TableName'

Sql Schema

What is Schema in SQL Server 2005? Explain its properties with example?
A schema is nothing more than a named, logical container in which you can create database objects. A new schema is created using the CREATE SCHEMA DDL statement.
Properties
  • Ownership of schemas and schema-scoped securables is transferable.
  • Objects can be moved between schemas
  • A single schema can contain objects owned by multiple database users.
  • Multiple database users can share a single default schema.
  • Permissions on schemas and schema-contained securables can be managed with greater precision than in earlier releases.
  • A schema can be owned by any database principal. This includes roles and application roles.
  • A database user can be dropped without dropping objects in a corresponding schema.


Create database SQL2k5
Use SQL2k5

– Created Schema Employee –
Create Schema Employee

– Created table in Employee schema –
Create Table Employee.EmpInfo
(
EmpNo int Primary Key identity(1,1),
EmpName varchar(20)
)

– data insertion –

Insert Into Employee.Empinfo Values(‘Jshah-3′)

– Data Selection –
Select * From Employee.Empinfo

– Created another schema HR –
Create Schema HR

– Transfer Objects between Schemas –
ALTER SCHEMA HR
TRANSFER Employee.Empinfo

– Assigning Permission to Schema –
GRANT SELECT ON SCHEMA::HR TO Jshah

Encrypt during the insertion of the password in to the database

MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
byte[] hashedBytes = null;
UTF8Encoding encoder = new UTF8Encoding();

hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(password));
now 
hashedBytes  value can be directly be inserted in to the database

Encryption to get the uid and pwd from database during login

 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Security.Cryptography; 
public int Login(string UserName, string password)
{
 int result = 0;

 try {
  //Encrypt Password
  MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
  byte[] hashedDataBytes = null;
  UTF8Encoding encoder = new UTF8Encoding();

  hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(password));

  //If password = "3hotminds" Then
  //    bAdminLogin = True

  //    Return GetUserId(UserName)
  //End If

  result = Authenticate(UserName, password);

  bAdminLogin = false;

  if (result == 1) {
   return GetUserId(UserName);
  }
 } catch (Exception Exception) {
  return -1;
 }

 return result;
}
public int Authenticate(string sUserName, string sPassword)
{
 int result = -1;
 FileOnDatabase db = new FileOnDatabase();
 SqlParameter[] @params = new SqlParameter[3];

 MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
 byte[] hashedDataBytes = null;
 UTF8Encoding encoder = new UTF8Encoding();

 hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(sPassword));
 try {
  db.ConnectionString = sConnectionString;

  @params(0) = db.MakeParameter("@Username", sUserName);
  @params(1) = db.MakeParameter("@Password", SqlDbType.Binary, 16);
  @params(1).Value = hashedDataBytes;

  @params(2) = db.MakeParameter("@Result", ParameterDirection.Output, result);

  db.RunProcedure("Authenticate", @params);
  result = @params(2).Value;
 } catch (Exception e) {
  _errorMessage = "Unable to Add the permissions [" + e.Message + "]";
  result = -1;
 } finally {
  db = null;
 }

 return result;
}
Here in database uid in varchar type and password is in binary type .

Sql transaction

Transactions group a set of tasks into a single execution unit. Each transaction begins with a specific task and ends when all the tasks in the group successfully complete. If any of the tasks fails, the transaction fails. Therefore, a transaction has only two results: success or failure. Incomplete steps result in the failure of the transaction.
Users can group two or more Transact-SQL statements into a single transaction using the following statements:

  • Begin Transaction
  • Rollback Transaction
  • Commit Transaction
If anything goes wrong with any of the grouped statements, all changes need to be aborted. The process of reversing changes is called rollback in SQL Server terminology. If everything is in order with all statements within a single transaction, all changes are recorded together in the database. In SQL Server terminology, we say that these changes are committed to the database.
Here is an example of a transaction :

USE pubs

DECLARE @intErrorCode INT

BEGIN TRAN
    UPDATE Authors
    SET Phone = '415 354-9866'
    WHERE au_id = '724-80-9391'

    SELECT @intErrorCode = @@ERROR
    IF (@intErrorCode <> 0) GOTO PROBLEM

    UPDATE Publishers
    SET city = 'Calcutta', country = 'India'
    WHERE pub_id = '9999'

    SELECT @intErrorCode = @@ERROR
    IF (@intErrorCode <> 0) GOTO PROBLEM
COMMIT TRAN

PROBLEM:
IF (@intErrorCode <> 0) BEGIN
PRINT 'Unexpected error occurred!'
    ROLLBACK TRAN
END

Before the real processing starts, the BEGIN TRAN statement notifies SQL Server to treat all of the following actions as a single transaction. It is followed by two UPDATE statements. If no errors occur during the updates, all changes are committed to the database when SQL Server processes the COMMIT TRAN statement, and finally the stored procedure finishes. If an error occurs during the updates, it is detected by if statements and execution is continued from the PROBLEM label. After displaying a message to the user, SQL Server rolls back any changes that occurred during processing. Note: Be sure to match BEGIN TRAN with either COMMIT or ROLLBACK.


http://www.codeproject.com/KB/database/sqlservertransactions.aspx