Pages

Monday, June 11, 2012

How to get client IP Address

How to get client IP Address / How to get machine IP Address.



  public string  getclientIP()
        {

            ManagementObjectSearcher objSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'");
            ManagementObjectCollection objCollection = objSearcher.Get();
            string Ip = "";
            foreach (ManagementObject obj in objCollection)
            {           
                string[] AddressList = (string[])obj["IPAddress"];
                foreach (string Address in AddressList)
                {

                  Ip=Address;
                    break;
                }             

            }
            return Ip;
        }

Thursday, June 7, 2012

How to get public IP Address of machine



        Dim client As New WebClient()


        ' Add a user agent header in case the requested URI contains a query.
        client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR1.0.3705;)")

        Dim baseurl As String = "http://checkip.dyndns.org/"

        Dim data As Stream = client.OpenRead(baseurl)
        Dim reader As New StreamReader(data)
        Dim s As String = reader.ReadToEnd()
        data.Close()
        reader.Close()
        s = s.Replace("<html><head><title>Current IP Check</title></head><body>", "").Replace("</body></html>", "").ToString()
        MessageBox.Show(s)

Saturday, March 24, 2012

how to get selected item from dropdownlist in javascript


var ddl=document.getElementById ("<%=DropDownList1.ClientID%>");
var text=ddl.options[ddl.selectedIndex].text;
alert(text); 

Friday, March 23, 2012

how to add remove items in dropdown list in java script

how to add remove items in dropdown list in java script in asp.net


it is very easy to add and remove items in javascript .

Here is the code for it...



<script type="text/javascript">
    function AddItem(Text,Value)
    {
        // Create an Option object for adding item to dropdownlist       
        var opt = document.createElement("option");

        // Add an Option object to Drop Down/List Box
        document.getElementById("DropDownList").options.add(opt);
        // Assign text and value to Option object
        opt.text = Text;
        opt.value = Value;

    }<script />


Enjoyyyy Programming..

Thursday, March 22, 2012

Call JavaScript function from code behind in asp.net

It is very easy to call javascript function from code behind asp.net .


In .cs code write


  string url = "yourpage.aspx?ManiFestNumber=" + value;
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "rates", "openWindow('" + url + "');", true);                  
       



in aspx page just write in this code 




<script type="text/javascript">

    function openWindow(url)
{
    var w = window.open(url, '', 'width=1,height=1,toolbar=0,status=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0');
    w.focus();
}





and Its done .........

Tuesday, March 6, 2012

Compare Validator for performing date validation


<asp:CompareValidator ID="CompareValidatorBookingDeadline" runat="server"
ControlToCompare="TextBoxTodayDate"
ControlToValidate="TextBoxExpiaryDate" Display="Dynamic"
ErrorMessage="Please check the date."
Operator="LessThanEqual"
Type="Date" 
ValueToCompare="<%= TextBoxSeminarDate.Text.ToShortString() %>">*</asp:CompareValidator>
The important thing is "ValueToCompare" property of the compare validator.

Saturday, March 3, 2012

Getting selected value from drop down using java script in asp.net



<asp:DropDownList ID="dropDown" runat="Server">

                                        <asp:ListItem Text="Item 1" Value="1" Selected="True"></asp:ListItem>

                                        <asp:ListItem Text="Item 2" Value="2"></asp:ListItem>

                                        <asp:ListItem Text="Item 3" Value="3"></asp:ListItem>

                                    </asp:DropDownList>

                                </td>

                                <td>

                                    <input type="button" value="Submit" onclick="GetDropDownValue('<%= dropDown.ClientID %>')" />




// Get DropDown value function GetDropDownValue(id) { alert(document.getElementById(id).value); }

Thursday, February 23, 2012

Math.Round() in java script

Syntax:
Math.round(x)


Example

<script type="text/javascript">

document.write(Math.round(0.75) + "<br />");
document.write(Math.round(0.50) + "<br />");
document.write(Math.round(0.25) + "<br />");
document.write(Math.round(-4.30) + "<br />");
document.write(Math.round(-4.88));

</script>


OUTPUT:


1
1
0
-4
-5

Wednesday, February 22, 2012

How to set default active view index

For making any default active view index . just write folloeing code in code behind

 WayBillMultiView.ActiveViewIndex = 0;

Tuesday, February 21, 2012

how to disable tabindex on controls in asp.net

For disabling tab just set TabIndex of any control to -1.

ex.

 <asp:TextBox ID="tbTotalAmount" runat="server" TabIndex="-1" ></asp:TextBox>

Monday, February 20, 2012

How to add Trigger to an UpdatePanel in code behind

//Creates a new async trigger
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
            //Sets the control that will trigger a post-back on the UpdatePanel
trigger.ControlID = "btnCommit";
//Sets the event name of the control
trigger.EventName = "Click";
//Adds the trigger to the UpdatePanels' triggers collection
pnlMain.Triggers.Add(trigger);

GridView Update All Rows At Once in asp.net

private void Update()
{
StringBuilder sb = new StringBuilder();
// build the query
foreach (GridViewRow row in GridView1.Rows)
{
sb.Append("UPDATE Users SET FirstName = '");
sb.Append((row.FindControl("txtFirstName") as TextBox).Text);
sb.Append("',");
sb.Append("LastName = '");
sb.Append((row.FindControl("txtLastName") as TextBox).Text);
sb.Append("', ");
sb.Append("ClassCode = '");
sb.Append((row.FindControl("txtClassCode") as TextBox).Text);
sb.Append("'");
sb.Append(" WHERE UserID = ");
sb.Append(Convert.ToInt32((row.FindControl("lblUserID") as Label).Text));
sb.Append(" ");
}
string connectionString =
"Server=HCUBE008;Database=School;Trusted_Connection=true";
SqlConnection myConnection = new SqlConnection(connectionString);
SqlCommand myCommand = new SqlCommand(sb.ToString(), myConnection);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}

Bind Data Dynamically To Drop Down List in gridview in asp.net


 ASPX Code:

 <asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="False" HeaderStyle-BackColor="#EDEDED" HeaderStyle-ForeColor="#184F46" HeaderStyle-Height="40px" HeaderStyle-HorizontalAlign="Center" OnRowDataBound="Gridview1_RowDataBound" SelectedRowStyle-BackColor="#F9CACA" ShowFooter="True" TabIndex="9" Width="100%">
<asp:TemplateField HeaderStyle-Height="30px" HeaderText="Package Type">
<ItemTemplate>
 <asp:DropDownList ID="ddlPackageType" runat="server"  Width="70px">
  </asp:DropDownList>
  </ItemTemplate>
  <HeaderStyle Height="30px" Width="8%" />
  <ItemStyle HorizontalAlign="Center" />
    </asp:TemplateField>
</GridView>


CODE Behind Code for Binding Data  :

protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
           
            DataSet dsPackageType = new DataSet();
      //Write Code For Getting data from Database and add it in dsPackageType Dataset .        

           if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Control ctrl = e.Row.FindControl("ddlPackageType");
                if (ctrl != null)
                {

                    DropDownList dd = ctrl as DropDownList;
                    dd.DataTextField = "PackageType";
                    dd.DataValueField= "Id";
                    dd.DataSource = dsPackageType;
                    dd.DataBind();
                    dd.Items.Insert(0, new ListItem("- Select -", "0"));

                }

            }
}

How to round numbers in java Script


Option1 : Math.Round()

Jave Script For rounding the numbers to required decimals ...

<script language="javascript" type="text/javascript">
function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
document.roundform.numberfield.value = parseFloat(newnumber); // Output the result to the form field (change for your
purposes)
}
</script>


Simple HTM For for Rounding the numbers 

<form name="roundform">
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<td>Round:</td>
<td><input type="text" name="numberfield" value="">
to
<input name="decimalfield" type="text" value="2" size="3">
decimal places</td>



Option 2: toFixed (beta)

Java Script
<script type="text/javascript">
function roundNumber(number, decimals) { // Arguments: number to round, number of decimal places
var newnumber = new Number(number+'').toFixed(parseInt(decimals));
document.roundform.roundedfield.value = parseFloat(newnumber); // Output the result to the form field (change for your purposes)
}
</script>

Sample HTML Form 

<form name="roundform">
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<td>Round:</td>
<td><input type="text" name="numberfield" value="">
to
<input name="decimalfield" type="text" value="2" size="3">
decimal places</td>













Tuesday, January 17, 2012

MX record



A mail exchanger record (MX record) is a type of resource record in the Domain Name System that specifies a mail server responsible for accepting email messages on behalf of a recipient's domain, and a preference value used to prioritize mail delivery if multiple mail servers are available. The set of MX records of a domain name specifies how email should be routed with the Simple Mail Transfer Protocol.



Wednesday, January 11, 2012

Features of SQL SERVER 2008R2



PowerPivot for SharePoint
PowerPivot for SharePoint adds shared services and infrastructure for loading, querying, and managing PowerPivot workbooks that you publish to a SharePoint 2010 server or farm. To create PowerPivot workbooks, you use PowerPivot for Excel. 


  PowerPivot for Excel
PowerPivot for Excel is an add-in to Excel 2010 that can be downloaded from the web and installed on client workstations. You use PowerPivot for Excel to assemble and create relationships in large amounts of data from different sources, and then use that data as the basis for PivotTables and other data visualization objects that support data analysis in Excel. 


  Multi-Server Administration and Data-Tier Application
The SQL Server Utility forms a central repository for performance data and management policies that tailor the operation of instances of the Database Engine that have been enrolled in the utility. It also includes a Utility Explorer for centralized management, and dashboards that report the state of the managed instances. A data-tier application (DAC) forms a single unit for developing, deploying, and managing the database objects used by an application.


  Master Data Services 
Master Data Services is comprised of a database, configuration tool, Web application, and Web service that you use to manage your organization's master data and maintain an auditable record of that data as it changes over time. You use models and hierarchies to group and organize data to prepare it for further use in business intelligence and reporting tools, data warehouses, and other operational systems. Master Data Services integrates with source systems and incorporates business rules to become the single source of master data across your organization.


  Features Supported by the Editions of SQL Server 2008 R2 
The largest database supported by SQL Server Express has been increased from 4 GB to 10 GB.


  Connecting to the Database Engine Using Extended Protection


SQL Server now supports Extended Protection, using service binding and channel binding to help prevent an authentication relay attack. Also, see Extended Protection for Authentication with Reporting Services.

Thursday, December 29, 2011

Enable Sqlserver access over the network

abling SQL Server 2008 (R2) access over Network
Posted on June 21, 2010

First: enable SQL Server itself to be accessed over the network
Open SQL Server Configuration Manager
Expand SQL Server Network Configuration and click Protocols for MSSQLSERVER

Doubleclick TCP/IP

Set Enabled to Yes


(click for large size)

Secondly: change the Windows Firewall to allow incoming connections on the TCP port of SQL Server
Open Windows Firewall with Advanced Security
Click on New Rule


(click for large size)

Now in the wizard you set the type of the rule to Port.



Hit Next.

On the second window you set the Specific local ports to 1433:



Hit Next.

Allow the connection.



Hit Next.

Now enable the checkboxes you want to. I set mine only to Private. Because I only need to access the SQL on my laptop at home:



Hit Next.



Hit Finish and you’re ready to develop SQL over network

How to: Enable Network Access in SQL Server Configuration Manager

To enable a network protocol


On the Start menu, choose All Programs, point to Microsoft SQL Server and then click SQL Server Configuration Manager.

Optionally, you can open Computer Manager by right-clicking My Computer and choosing Manage. In Computer Management, expand Services and Applications, expand SQL Server Configuration Manager.


Expand SQL Server Network Configuration, and then click Protocols for InstanceName.


In the list of protocols, right-click the protocol you want to enable, and then click Enable.

The icon for the protocol will change to show that the protocol is enabled.


To disable the protocol, follow the same steps, but choose Disable in step 3.
To configure a network protocol


On the Start menu, right-click My Computer, and then choose Manage.


In Computer Management, expand Services and Applications, expand SQL Server Configuration Manager, expand Server Network Configuration, expand Protocols for InstanceName, and then click the protocol you want to configure.

Access sql server 2008 over network

re trying to connect to SQL Server 2008 Express remotely without enable remote connection first, you may see these error messages:
“Cannot connect to SQL-Server-Instance-Name
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 28 – Server doesn’t support requested protocol) (Microsoft SQL Server)”

“Cannot connect to SQL-Server-Instance-Name
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified) (Microsoft SQL Server)”

“Cannot connect to SQL-Server-Instance-Name
Login failed for user ‘username‘. (Microsoft SQL Server, Error: 18456)”


To enable remote connection on SQL Server 2008 Express, see the step below:
Start SQL Server Browser service if it’s not started yet. SQL Server Browser listens for incoming requests for Microsoft SQL Server resources and provides information about SQL Server instances installed on the computer.
Enable TCP/IP protocol for SQL Server 2008 Express to accept remote connection.
(Optional) Change Server Authentication to SQL Server and Windows Authentication. By default, SQL Server 2008 Express allows only Windows Authentication mode so you can connect to the SQL Server with current user log-on credential. If you want to specify user for connect to the SQL Server, you have to change Server Authentication to SQL Server and Windows Authentication.

Note: In SQL Server 2008 Express, there isn’t SQL Server Surface Area Configuration so you have to configure from SQL Server Configuration Manager instead.
Step-by-step
Open SQL Server Configuration Manager. Click Start -> Programs -> Microsoft SQL Server 2008 -> Configuration Tools -> SQL Server Configuration Manager.

On SQL Server Configuration Manager, select SQL Server Services on the left window. If the state on SQL Server Browser is not running, you have to configure and start the service. Otherwise, you can skip to step 6.

Double-click on SQL Server Browser, the Properties window will show up. Set the account for start SQL Server Browser Service. In this example, I set to Local Service account.

On SQL Server Browser Properties, move to Service tab and change Start Mode to Automatic. Therefore, the service will be start automatically when the computer starts. Click OK to apply changes.

Back to SQL Server Configuration Manager, right-click on SQL Server Bowser on the right window and select Start to start the service.

On the left window, expand SQL Server Network Configuration -> Protocols for SQLEXPRESS. You see that TCP/IP protocol status is disabled.

Right-click on TCP/IP and select Enable to enable the protocol.

There is a pop-up shown up that you have to restart the SQL Service to apply changes.

On the left window, select SQL Server Services. Select SQL Server (SQLEXPRESS) on the right window -> click Restart. The SQL Server service will be restarted.

Open Microsoft SQL Server Management Studio and connect to the SQL Server 2008 Express.

Right-click on the SQL Server Instance and select Properties.

On Server Properties, select Security on the left window. Then, select SQL Server and Windows Authentication mode.

Again, there is a pop-up shown up that you have to restart the SQL Service to apply changes.

Right-click on the SQL Server Instance and select Restart.

That’s it. Now you should be able to connect to the SQL Server 2008 Express remotely.

Wednesday, December 28, 2011

Java script code for login on enter key press

function clickButton(e, buttonid){

      var evt = e ? e : window.event;

      var bt = document.getElementById(buttonid);

      if (bt){

          if (evt.keyCode == 13){

                bt.click();

                return false;

          }

      }

}