Thursday, 20 December 2012

  <script type="text/javascript" language="javascript">
    function checkValidateData()
    {
    var che =document.getElementById("txtChe.Text");
    var phy=document.getElementById("txtPhy.Text");
    var math=document.getElementById("txtMath.Text");
 
//    if(isNaN(che))
//    {
//    alert('Please Enter Marks');
//    return true;
//    }
    
    var uid;
    var temp=document.getElementById("<%=txtChe.ClientID %>");
    uid=temp.value;
    if(uid=="")
    {
    alert ('Please Enter UserName');
    return false;
    }

    if(isNaN(uid))
    {
    alert('Please Enter number');
    uid.Focus();
    return false;
    }
   
    }
    </script>



  Grade

protected void Button1_Click(object sender, EventArgs e)
        {
            if (int.Parse(txtphy.Text) < 35 || int.Parse(txtphy.Text) < 35 || int.Parse(txtChe.Text) < 35)
            {
                Response.Write("Fail");
            }
            else
            {
                txtTot.Text = Convert.ToString((int.Parse(txtphy.Text) + int.Parse(txtMaths.Text) + int.Parse(txtChe.Text)));
                txtper.Text = Convert.ToString(int.Parse(txtTot.Text) / 3);

                if (int.Parse(txtper.Text) == 35 && int.Parse(txtper.Text) >= 49)
                {
                    Response.Write("Your Grad Id C");
                }
                else
                    if (int.Parse(txtper.Text) > 49 && int.Parse(txtper.Text) <= 59) { Response.Write("Your Grad Id B"); }
                    else
                        if (int.Parse(txtper.Text) >= 60 && int.Parse(txtper.Text) <= 65) { Response.Write("Your Grad Id A"); }
                        else
                            if (int.Parse(txtper.Text) > 65 && int.Parse(txtper.Text) <= 75) { Response.Write("Your Grad Id A+"); }


             }
        }


 ---------------------------------------------





  <script type="text/javascript" language="javascript">
    function checkValidateData()
    {
    var che =document.getElementById("txtChe.Text");
    var phy=document.getElementById("txtPhy.Text");
    var math=document.getElementById("txtMath.Text");
 
//    if(isNaN(che))
//    {
//    alert('Please Enter Marks');
//    return true;
//    }
    
var uid;
var temp=document.getElementById("<%=txtChe.ClientID %>");
uid=temp.value;
if(uid=="")
{
alert ('Please Enter UserName');
return false;
}
   
   
    }
    </script>
 

Tuesday, 18 December 2012

Cross Page Posting

Cross Page Posting



Response.Write(
((TextBox)this.PreviousPage.FindControl("MyTextBox")).Text)

In order to provide the strongly typed access to previous page, you can specify the previous page in PreviousPageType directive; since you have strongly typed reference of previous page you can now easily access its public members without any typecasting. Lets see how (here login page postbacks to UserAuthenticate page).

Login.aspx
<asp:Textbox ID="TextBoxUserName" Runat="server" />
<asp:Textbox ID="TextBoxPassword" Runat="server" />
<asp:Button ID="ButtonLogin" Runat="server" Text="Login"
         PostBackUrl="UserAuthenticate.aspx" />

Expose the following properties in code behind file
public TextBox UserName
{
    get
    {
        return TextBoxUserName;
    }
}

public TextBox Password
{
    get
    {
        return TextBoxPassword;
    }
}

UserAuthenticate.aspx
<%@ PreviousPageType VirtualPath="~/Login.aspx" %>
<script runat="server">   
protected void Page_Load(object sender, System.EventArgs e)
{
    String username = PreviousPage.UserName.Text;
    String password = PreviousPage.Password.Text;
    // Authenticate username/password
}

Monday, 17 December 2012

WCF and Const,Readonly,Static


 WCF Windows Communication Foundation



Q1. What is WCF?
WCF stands for Windows Communication Foundation. It is a Software development kit for developing services on Windows. WCF is introduced in .NET 3.0. in the System.ServiceModel namespace. WCF is based on basic concepts of Service oriented architecture (SOA)

Q2. What is endpoint in WCF service?
The endpoint is an Interface which defines how a client will communicate with the service. It consists of three main points: Address,Binding and Contract.

Q3. Explain Address,Binding and contract for a WCF Service?
Address:Address defines where the service resides.
Binding:Binding defines how to communicate with the service.
Contract:Contract defines what is done by the service.

Q4. What are the various address format in WCF?
a)HTTP Address Format:--> http://localhost:
b)TCP Address Format:--> net.tcp://localhost:
c)MSMQ Address Format:--> net.msmq://localhost:

Q5. What are the types of binding available in WCF?
A binding is identified by the transport it supports and the encoding it uses. Transport may be HTTP,TCP etc and encoding may be text,binary etc. The popular types of binding may be as below:
a)BasicHttpBinding
b)NetTcpBinding
c)WSHttpBinding
d)NetMsmqBinding

Q6. What are the types of contract available in WCF?

The main contracts are:
a)Service Contract:Describes what operations the client can perform.
b)Operation Contract : defines the method inside Interface of Service.
c)Data Contract:Defines what data types are passed
d)Message Contract:Defines wheather a service can interact directly with messages

Q7. What are the various ways of hosting a WCF Service?
a)IIS b)Self Hosting c)WAS (Windows Activation Service)

Q8. WWhat is the proxy for WCF Service?

A proxy is a class by which a service client can Interact with the service.
By the use of proxy in the client application we are able to call the different methods exposed by the service


Q9. How can we create Proxy for the WCF Service?

We can create proxy using the tool svcutil.exe after creating the service.
We can use the following command at command line.
svcutil.exe *.wsdl *.xsd /language:C# /out:SampleProxy.cs /config:app.config

Q10.What is the difference between WCF Service and Web Service?
a)WCF Service supports both http and tcp protocol while webservice supports only http protocol.
b)WCF Service is more flexible than web service.

Q11.What is DataContract and ServiceContract?Explain
Data represented by creating DataContract which expose the
data which will be transefered /consumend from the serive
to its clients.

**Operations which is the functions provided by this
service.

To write an operation on WCF,you have to write it as an
interface,This interface contains the "Signature" of the
methods tagged by ServiceContract attribute,and all methods
signature will be impelemtned on this interface tagged with
OperationContract attribute.

and to implement these serivce contract you have to create
a class which implement the interface and the actual
implementation will be on that class





const and readonly perform a similar function on data members, but they have a few important differences.

const

A constant member is defined at compile time and cannot be changed at runtime. Constants are declared as a field, using the const keyword and must be initialized as they are declared. For example;
public class MyClass
{
  public const double PI = 3.14159;
}
PI cannot be changed in the application anywhere else in the code as this will cause a compiler error.
Constants must be a value type (sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool), an enumeration, a string literal, or a reference to null.
Since classes or structures are initialized at run time with the new keyword, and not at compile time, you can't set a constant to a class or structure.
Constants can be marked as public, private, protected, internal, or protected internal.
Constants are accessed as if they were static fields, although they cannot use the static keyword.
To use a constant outside of the class that it is declared in, you must fully qualify it using the class name.

readonly

A read only member is like a constant in that it represents an unchanging value. The difference is that a readonly member can be initialized at runtime, in a constructor as well being able to be initialized as they are declared. For example:
public class MyClass
{
  public readonly double PI = 3.14159;
}




public class MyClass
{
  public readonly double PI;
 
  public MyClass()
  {
    PI = 3.14159;
  }
}
Because a readonly field can be initialized either at the declaration or in a constructor, readonly fields can have different values depending on the constructor used. A readonly field can also be used for runtime constants as in the following example:
public static readonly uint l1 = (uint)DateTime.Now.Ticks;
Notes
  • readonly members are not implicitly static, and therefore the static keyword can be applied to a readonly field explicitly if required.
  • A readonly member can hold a complex object by using the new keyword at initialization.


[edit]

static

Use of the static modifier to declare a static member, means that the member is no longer tied to a specific object. This means that the member can be accessed without creating an instance of the class. Only one copy of static fields and events exists, and static methods and properties can only access static fields and static events. For example:
public class Car
{
  public static int NumberOfWheels = 4;
}
The static modifier can be used with classes, fields, methods, properties, operators, events and constructors, but cannot be used with indexers, destructors, or types other than classes.
static members are initialized before the static member is accessed for the first time, and before the static constructor, if any is called. To access a static class member, use the name of the class instead of a variable name to specify the location of the member. For example:
int i = Car.NumberOfWheels;

Friday, 21 September 2012

Perform GridView Operation

   Perform GridView Operation 




Getting perticular record in Texboxes when clicked on Gridview

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {

                //string str = e.CommandName;
                int rowi = Convert.ToInt16(e.CommandArgument);
                GridViewRow row = GridView1.Rows[rowi];
                txtNo.Text = row.Cells[0].Text;

                txtEName.Text = row.Cells[1].Text;
                txtEmail.Text = row.Cells[2].Text;
                txtTechnology.Text = row.Cells[3].Text;
            }
       }





Delete perticular Record in gridview

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int EmpId = (int)GridView1.DataKeys[e.RowIndex].Value;


            objDBEmpManager.DeleteData(EmpId);
          
               // btnSave.Text = "Deleted";
                BindGrid();
        }


          public Boolean DeleteData(int EmpID)
        {
        objSqlCommand = new SqlCommand("USP_tDMLApp_Delete",     objSqlConnection);
            objSqlCommand.CommandType = CommandType.StoredProcedure;
            objSqlCommand.Parameters.AddWithValue("EmpId", EmpID);
            objSqlConnection.Open();
            objSqlCommand.ExecuteNonQuery();
            objSqlConnection.Close();
            return true;
        }







Get gridview value 1 page to another page trough query string




<asp:GridView ID="GridView1" runat="server" 
              AutoGenerateColumns="False" 
              DataSourceID="SqlDataSource1">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="ID,Name,Location" 
DataNavigateUrlFormatString=
"Default2.aspx?id={0}&name={1}&loc={2}" 
Text="Transfer values to other page" />
<asp:BoundField DataField="ID" HeaderText="ID" 
                SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" 
                SortExpression="Name" />
<asp:BoundField DataField="Location" HeaderText="Location" 
                SortExpression="Location" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [ID], [Name], [Location] FROM [Details]">
</asp:SqlDataSource>

protected void Page_Load(object sender, EventArgs e)
    {
        string strID = Request.QueryString["id"];
        string strName = Request.QueryString["name"];
        string strLocation = Request.QueryString["loc"];
        lblID.Text = strID;
        lblName.Text = strName;
        lblLocation.Text = strLocation;
}   



                      Just Logic in mini Prg.


        public string Reverse(string rev)
         {
            char[] arr = rev.ToCharArray();
            Array.Reverse(arr);
            return new string(arr);
         }
        public string SortAlfabet(string rev)
        {
            char[] arr = rev.ToCharArray();
            Array.Sort<char>(arr);
            return new string(arr);
        }
        public int Count(string no)
        {
            char[] arr = no.ToCharArray();
            int res = arr.Length;
            return res;
        }