Monday 26 September 2011

How to Refresh Parent Page

Question : The Question arise that . i have a data control and i click on this template then an window open offcourse this is the child window and we show some data on this child window . i want refresh the parent page after load the child window .How to do this
Answer:
lets take an example what you want simply when user see her/his mail then after clicking the mail the row color is chage . Exactly we want this in your project .. So there are a solution ..
write the following code on your child window page laod  or where you want

const string cRefreshParent = "<script language='javascript'>" +

    "  window.opener.document.forms(0).submit();" + "</script>";
    const string cRefreshParentKey = "RefreshParentKey";
    if (!this.Page.ClientScript.IsClientScriptBlockRegistered(cRefreshParentKey))
    {
        this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
        cRefreshParentKey, cRefreshParent);
    }

I think   this solution is quite easy but very useful if you want to create Web applications in which  open child window and you want to refersh parent page.

Friday 9 September 2011

Difference Between Dll and EXE

This  question is genrally asked in interview and the answer is
DLL:
1)it is not self executable
2)it runs in application process memory
3)it has no entry point
4)it is reusable
5)Out Process Server

Exe:
1)it is self executable
2)it runs in own memory
3)it have main function(Entry point)
4)it is self executable
5) In Process Server
-------------------------------
Some differnce related to Space
DLL file is a Library File which supports a executable file.
DLL stands for Dynamic Link Library - it is a library file which is linked at runtime (ie. dynamically) rather than at compile-time.an exe has its own individual address space, whereas a dll have one address space, thus it can be shared.A dll can be "dynamically" loaded and unloaded from memory, allowing an application to take up less space than it normally would when its not using the functions in that dll.
-----------------------------------------------------------------------------------

when we read above differnce then there are one Question what is IN process server and out process server 
then the answer is
  • Out-of-process server components. Out-of-process server components are always EXE files.
  • In-process server components. In-process server components are always DLL files.
The difference between these server component types is with respect to the client application.
When a server component runs out-of-process with respect to its client, it has the following characteristics:
  • It can run as a standalone application completely apart from the client.
  • It does not share the same address space under the operating system.
When a server component runs in-process with its client, it has these important features:
  • The server component and client share the same executable space under the operating system.
  • The server component and client share some of the same memory.
As you might imagine, there are pros and cons to both in-process and out-of-process server components.
----------------------------------------------------------------------------------------------
In process server:A library (DLL) running in the same process space as the client, for example, an ActiveX control embedded in a Web page viewed under Internet Explorer or Netscape. Here, the ActiveX control is downloaded to the client machine and invoked within the same process as the Web browser.The client communicates with the in-process server using direct calls to the COM interface.

Out process server:Another application (EXE) running in a different process space but on the same machine as the client. For example, an Excel spreadsheet embedded in a Word document are two separate applications running on the same machine.The local server uses COM to communicate with the client.

Thursday 8 September 2011

union and union all in SQL Server

Which  is faster UNION ALL or UNION?
Firstly we have to know that what is union

Combines the results of two or more queries into a single result set that includes all the rows that belong to all queries in the union. The UNION operation is different from using joins that combine columns from two tables.
The following are basic rules for combining the result sets of two queries by using UNION:
  • The number and the order of the columns must be the same in all queries.
  • The data types must be compatible.
    (from msdn) 



    lets come to our concern question the answer is

    UNION ALL faster than a UNION because for union operation server needs to remove the duplicate values but for union all its not. Thats why the UNOIN ALL is fater than UNION Operation. It is recommended that if you know that the union set operation never returns duplicate values than you must use UNION ALL instead of UNION.


Story of Appreciation

One young academically excellent person went to apply for a managerial position in a big company.

He passed the first interview, the director did the last interview, made the last decision.

The director discovered from the CV that the youth's academic achievements were excellent all the way, from the secondary school until the postgraduate research, never had a year when he did not score.

The director asked, "Did you obtain any scholarships in school?" the youth answered "none".

The director asked, " Was it your father who paid for your school fees?" The youth answered, "My father passed away when I was one year old, it was my mother who paid for my school fees.

The director asked, " Where did your mother work?" The youth answered, "My mother worked as clothes cleaner. The director requested the youth to show his hands. The youth showed a pair of hands that were smooth and perfect.

The director asked, " Have you ever helped your mother wash the clothes before?" The youth answered, "Never, my mother always wanted me to study and read more books. Furthermore, my mother can wash clothes faster than me.

The director said, "I have a request. When you go back today, go and clean your mother's hands, and then see me tomorrow morning.*

The youth felt that his chance of landing the job was high. When he went back, he happily requested his mother to let him clean her hands. His
mother felt strange, happy but with mixed feelings, she showed her hands to the kid.

The youth cleaned his mother's hands slowly. His tear fell as he did that. It was the first time he noticed that his mother's hands were so wrinkled, and there were so many bruises in her hands. Some bruises were so painful that his mother shivered when they were cleaned with water.

This was the first time the youth realized that it was this pair of hands that washed the clothes everyday to enable him to pay the school fee. The bruises in the mother's hands were the price that the mother had to pay for his graduation, academic excellence and his future.

After finishing the cleaning of his mother hands, the youth quietly washed all the remaining clothes for his mother.

That night, mother and son talked for a very long time.

Next morning, the youth went to the director's office.

The Director noticed the tears in the youth's eyes, asked: " Can you tell me what have you done and learned yesterday in your house?"

The youth answered, " I cleaned my mother's hand, and also finished cleaning all the remaining clothes'

The Director asked, " please tell me your feelings."

The youth said, Number 1, I know now what is appreciation. Without my mother, there would not the successful me today. Number 2, by working together and helping my mother, only I now realize how difficult and tough it is to get something done. Number 3, I have come to appreciate the importance and value of family relationship.

The director said, " This is what I am looking for to be my manager.
I want to recruit a person who can appreciate the help of others, a person who knows the sufferings of others to get things done, and a person who would not put money as his only goal in life. You are hired.

Later on, this young person worked very hard, and received the respect of his subordinates. Every employee worked diligently and as a team. The company's performance improved tremendously.
---------------------------------
this is the heart toching story for me i dont know were i read this story but i like very much so i put there

Thanks
Rohit Srivastava





Wednesday 7 September 2011

SQL Server Query

Here are the test table in which there are two field

create table  test
(
name varchar(30),
id varchar(30)
)

insert into test values('A1')

name              id
A                  1
B                 2
C                  3
C                 4
A                   2
A                   3
-------------------------
and i want to result  like below

A     1, 2, 3
B     2
C     3, 4

below query will help u as a tonic
SELECT [name], STUFF((SELECT ', ' + [id]
                       FROM test  T2
                          WHERE T1.[name] = T2.[name]
                      Order By [id]
                FOR XML PATH('')),1,1,'') AS [Subject Books]
           FROM test T1
           GROUP BY [name]


-----------------------------
Hope this will help you
Thanks
Rohit Srivastava

Tuesday 6 September 2011

Update Specific Field Value in SQL Server

How to Update Some Specific Value IN Sql Server

UPDATE tblLocation SET LocationName = REPLACE(LocationName,'hall','Hall');
it can easily understand by Below example
lets my table name is Party
id  PartyName                       active
1    Rohit                                   1
2    Dealer Rohit                              1
3    Owner                                1
4    Builder Rohit                              1
-----------------------------
in above we want to update partyname field value where ROHIT replace to Riya then query is

UPDATE Party  SET PartyName= REPLACE(PartyName,'Rohit','Riya');
---------------------------------------------------------------------------------------
2..Another Query
How to Update First Word Is Always Capital  in SQL Server..
To Acompolish this we create a function and call this like below

 CREATE FUNCTION [dbo].[properCase](@string varchar(8000)) RETURNS varchar(8000) AS
BEGIN 
    SET @string = LOWER(@string)
    DECLARE @i INT
    SET @i = ASCII('a')
    WHILE @i <= ASCII('z')
    BEGIN
        SET @string = REPLACE( @string, ' ' + CHAR(@i), ' ' + CHAR(@i-32))
        SET @i = @i + 1
    END
    SET @string = CHAR(ASCII(LEFT(@string, 1))-32) + RIGHT(@string, LEN(@string)-1)
    RETURN @string
END

 And Call this function like this  in ur Query

 UPDATE urTable SET name=[dbo].[properCase](name)

this set first letter of ur word is capital and other is Small , According to Ur Requirement

Hop This will help u
Rohit Srivastava

How to check string value is number or not

Hi friends there are the simple javascript method for this
string number = "100";
if (number.All(Char.IsDigit))
{
Console.Write("{0} is a valid number!", number);
}
else
{
Console.Write("{0} is not a valid number!", number);
 } 
 ----------------------------------------------------------
Hope this will help you 
thanks 
Rohit Srivastava

Monday 5 September 2011

Set Focus On Text Box when Page Load

Hi Question arises in our mind is how to default focus to a asp control when the page loads  . First way is use the javascript other is given below
  This is another extremely simple thing that can be done without resorting to writing JavaScript.  If you only have a single textbox (or two) on a page why should the user have to click in the textbox to start typing?  Shouldn't the cursor already be blinking in the textbox so they can type away?
Using the DefaultFocus property of the HtmlForm control you can easily do this.
<body>
  <form id="frm" DefaultFocus="txtUserName" runat="server">
    <!--Write your page code here-->
  </form>
</body>

Hope this will benificail for all

Maintain Scroll Position in ASP .net

Hi there are a Question to  maintain the position of the scrollbar on postbacks. In old .Net frameworks (ASP.NET 1.1 or earlier) it was a pain to maintain the position of the scrollbar when doing a postback operation you have to write hell lot of javascript code. This was especially true when you had a grid on the page and went to edit a specific row.  Instead of staying on the desired row, the page would reload and you would be placed back at the top and have to scroll down.
In ASP.NET 2.0 and onwards you can simply add the MaintainScrollPostionOnPostBack attribute to the Page directive:
<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeFile="abc.aspx.cs" Inherits="WebApplication1.abc" %>

Thursday 1 September 2011

Send mail in asp.net

  public static bool sendMail(string from, string subject, string to, string bcc, string body)
    {
        MailAddress mailAddress = new MailAddress(from);
        MailMessage mail = new MailMessage();
        mail.To.Add(to.ToString());
        mail.From = mailAddress;
        mail.Subject = subject;

        mail.Body = body;
        mail.IsBodyHtml = true;
        mail.Priority = MailPriority.High;
        SmtpClient smtp = new SmtpClient();
        bool flag = true;
        try
        {

            smtp.Host = smtp.gmail.com; //Or Your SMTP Server Address
            smtp.Credentials = new System.Net.NetworkCredential(your gmail id, ur gmail password);
//            smtp.Credentials = new System.Net.NetworkCredential(rrohit_0087@gmail.com,******);
            //Or your Smtp Email ID and Password
            smtp.EnableSsl = true;
            smtp.Send(mail);
        }
        catch
        {
            flag = false;
        }
        return flag;
    }

this is the method for sending the mail in this there are 5 parameter pass in this ..
in first enter the pass the gmail id by which you want to send mail
in second pass the subject of the mail
in third pass the id in which you want to send the mail .
in fourth pass the bcc id
in fourth pass the body of mail means what you want to send
---------------------------------------------------------------------------