C# get ip address (Client IP Address Asp.net)

C# get IP address (Client IP Address Asp.net)

In this tutorial, I will discuss "C# get IP address (Client IP Address Asp.net)". There are several methods to find clients or visitor's IP addresses. Asp.net provides us, inbuilt class, and function by which we easily find the IP address of the client's system.

Every time when you developed a software there is a requirement for the IP address just because we can track the end-users IP address and identify who actually doing the data modification. It is a good practice to implement IP address concept in your application.

Before Implementing the IP address code in your application. Let's know how to check IP address in your system.

How to check the IP address

Step 1. Open command prompt by pressing window key + R and enter cmd and search.
Step 2. Type ipconfig to know your actual IP address. See below img.

C# get ip address (Client IP Address Asp.net)
Get Client Ip in Asp.net C#


There are many ways you can find out IP address in c# asp.net, some of are working on local server and some are working on the remote server. The method is given below, follow the step to get IP address.

Method 1:

The first method is very simple and easy, you just need to write only one line of code. 
Note: This method does not give actual IP address in the local server if want to see IP address use remote server.

public string getIpAddress()
{
string ipAddress = HttpContext.Current.Request.UserHostAddress.ToString();
return ipAddress;
}

Method 2:

This method is actually the very best way to find the IP address it will work on both servers local as well as remote server/ production server. Don't forget to use these Name Space.

using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;



public static string GetLocalIPAddress()
    {
        var host = Dns.GetHostEntry(Dns.GetHostName());
        foreach (var ip in host.AddressList)
        {
            if (ip.AddressFamily == AddressFamily.InterNetwork)
            {
                return ip.ToString();
            }
        }
        throw new Exception("No network adapters with an IPv4 address in the system!");
    }

My recommendation is to use Method 2 to get the proper IP address. I hope you will like this C# get ip address post.

Read More

What is HTML ? Advantages and disadvantages of HTML all about html attribute,element,tag

"Advantage and Disadvantage of HTML" (HyperText Markup Language)

"What is HTML"


"HTML" stands for  HyperText Markup language. Basically, HTML is used to mark up a web page by using HTML attributes. Html was created by "Sir Berners-Lee" in 1991. Later on, in 1995 HTML 2.0 was published with some extra specification. After the success of  HTML 2.0 in 1999 HTML 4.0.1 was published. Though HTML 4.01 version is used currently we are having HTML-5 version which is an extension to HTML 4.01, and this version was published in 2012.  

Every language has it own block where we write our code similarly HTML have also it's own block which starts with <HTML> and ends with </HTML>.

Html code is written by the programmer and it is saved as .html or .htm extension and viewed by any respected browser (i.e. Google Chrome, Firefox etc). To learn HTML there is no need backup of any other language. You can easily learn HTML by knowing some tag of HTML and some other basic thing. 

HTML Advantages


As we know that HTML is a markup language which is used for formatting web pages of websites. Here are some advantages and disadvantages of HTML which is following as:

1.HTML can be integrated easily with Javascript, Jquery and CSS.
2.Easy to understand due to a relevant and memorable HTML tag.
3.HTML supported by all browsers (i.e. Google Chrome, Opera Mini, Mozilla Firefox and         many more browser)
4.HTML is light weighted and fast to load.
5.HTML is a free and open-source markup language, you don't need to buy a single line of code to design your website.
6.HTML have many tag and attributes which will short your line of code. 

HTML Disadvantages

1. By Html, we can develop only static web pages if you want to develop Dynamic webpages you need the knowledge of some other programming languages like .Net, Java and also have knowledge of some scripting language (JQuery, JavaScript).
2. Security Features is less in HTML. 

Some major reason why to use HTML


HTML is a lightweight and fast loading markup language, every time when you hit the server through your browser you get the response in the form of HTML and CSS. 

HTML has the support of many tags which make your web page looks attractive and noticeable.

Recently, HTML5 added so many tag and element which helps to develop a page in professional manners.

What is HTML Attributes,HTML Tags and HTML Elements

HTML Attributes

HTML attributes are a special type of words which is used to control the element's behaviour inside the opening tag. The actual use of HTML attributes is to modify the default functionality of an HTML element.

Here are some different type of HTML attributes
1.Required attribute
2.Optional attribute
3.Standard attribute
4.Event attribute

Example of HTML attributes


<a href="www.example.com">Google</a>
<p align="right">This is Element in HTML</p>


HTML attributes contain Key-Value pair information. In the above example, 'href' is an attribute whereas <a> is an anchor tag, we can say that Tags can also have attributes. HTML attributes contain some extra information for the tag so that we can modify any tag at my end.HTML attributes is just a modifier of HTML element type.

HTM Tag

HTM Tag is a special type of words which contains opening and closing angle bracket(< >). HTML tag example.
Some HTML Tag which is used most during web page development

<p> 
<b> 
<ol>
<ul>
<tr>
<td>
<html>
<figure> 
<button> 
<head> 
<header>
<option>
<progress>
<script>
<table>

HTML Elements 

HTML Elements contains some kind of information which is available with in HTML tag. HTML Element example.

<h1>I am heading as well as HTML elements</h1> 



What is HTML ? Advantages and disadvantages of HTML all about html attribute,element,tag
Advantages and disadvantages of HTML



I hope you like the advantages and disadvantages of HTML, Still, if you have any doubt about it, feel free to comment we will help you.

Read More

23 Typescript interview questions and answers for beginners

Welcome to Typescript interview questions (pdf) and answers for beginners, Here are some tricky typescript interview question and answers collection which is asked in the interview. May it will help you to crack your typescript interview.


Typescript interview questions and answers for beginners
Typescript interview questions and answers


1. What is namespace in Typescript? Write the declaration of the namespace.

I think Everyone familiar with the namespace of other languages, here also in TypeScript a namespace is just a collection of classes by which we can logically categories. If we want to access any class from outside of the namespace then we need to export keyword.


namespace People
{
      export class Boss
      {     
      }
      export class Employee
      {      
      }
      export interface Iofficework

 }



2. What is Typescript?


TypeScript is known as Object-oriented programming language developed and maintained by Microsoft. Which is provide you to optional parameters, classes, and interfaces.TypeScript is nothing but JavaScript and some additional features i.e. ES6 features. Whenever we compile the TypeScript code it first converts in JavaScript then it runs and we get output.


3.Difference between typescript and javascript?

1. Typescript is a superset of JavaScript whereas JavaScript is a scripting language.
2. Typescript has an interface concept but JavaScript havan't.
3.TypeScript doesn't run in the browser where JavaScript runs.
4.TypeScript has classes whereas JavaScript has functions.
5. Typescript support module whereas JavaScript doesn't support modules.
6. In typescript Number, a string is the interfaces whereas In, JavaScript Number, string are the Object.


4. What are the key features of typescript?

TypeScript supports different browsers or node.js versions and optimizes the resulting JavaScript. It is much easier to write clean, consistent code across a project and development team.


5.When to use a super keyword in typescript.

In typescript, Super keyword is used to reference base class properties and the base class constructor.

6.How to access static methods in TypeScript



7. What Are Classes In Typescript?

The concept of classes is very similar to .NET/Java. A Class can have constructor, member variables, properties, and methods. TypeScript also allows access to modifiers “private” and “public” for member variables and functions.

8. Tell me the command for installing typescript.

npm install -g typescript

9. What Are The Benefits Of Typescript?

TypeScript has the following benefits:

1.Intellisense
2Impose coding guidelines
3.Offers type checking
4. It helps in code structuring
5.Compile time error checking
6. Use class-based object-oriented programming

10. What is the typescript extension and how you compile?

Typescript extension is '.ts'. It is just a javascript file, when we compile typescript file, just after compilation it convert into '.js' file.

Step to compile a typescript program
1. tsc 'your typeScript File Name'
For example, to compile “program.ts”:
tsc program.ts

After compilation, you will get
program.js


11. How to declare a variable in Typescript?


var name:string="sham"
var phone:string="123456"


12. How do you declare an undefined variable?

var name:string;

var phone:int;

13. How to declare and initialize an array in Typescript?

var names:string[];       -- Declaration

names=["a","b","c","d"]   -- Initialization

14. How to achieve inheritance in Typescript?


15. How to make a module in Typescript?

https://johnpapa.net/typescriptpost4/

16. What is the role of constructor in Typescript?

A constructor is responsible for initializing the variable of the class.

17. How to initialize the static variables?


class office
{
   static phoneNo:number=101;
   office.phoneNo=106
   console.log(office.phoneNo) ;

18. What is the difference between var and let in Typescript?

1.var declaration done at function scoped and let declaration done at block scoped.
2.var allow you to re-declare the same variable in the same scope. whereas let will not

19.How to define a global variable in a typescript module.

https://github.com/Microsoft/TypeScript/issues/18237

20.How to export a variable.



export var demo = [1,2,3];

21. What is the role of var keyword in typescript?

var is key it helps us to create an object of a class.

22. How to Convert string to number in TypeScript?


   name:string;
   empcode:number;0
   //convert string to number
   this.empcode = Number(name);


23. Can we debug Typescript file?

Yes, With the help of .js source map file.

24. What are the classes in TypeScript?

Typescript class is very similar to other languages like (.Net, Java). As we know that class can have constructor, member, variable and methods.

25. What are the benefits of Typescript?

1. ES7 and ES6 Features support.
2. User-friendly for Java and .Net programmer.
3. Intellisense.
4. Object Oriented programming support.



TAG: Typescript interview questions and answers for beginners, Typescript interview question and answers, beginner typescript question and answer

Read More

Onchange Event In JQuery For Dropdown Example

Onchange Event In JQuery For Dropdown Example asp.net / HTML:

In this post, I am going to discuss the onchange event in jquery for dropdown for the Asp.net text box as well as the HTML textbox. If you think both controls (Asp.net and HTML) are the same then I will say no every time whenever  asp.net page runs it converted into HTML with some page life cycle (PLC) steps. If You take asp.net ControlID="ddlcountry" after page rendering it will be converted into id="ct100_ddlcountry". 

So here we need to take care of these things while calling the asp.net controls in JQuery. Let's have a look.

change Event In JQuery For Dropdown


Jquery Onchange Event with Asp.net DropDown


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script>
        $(document).ready(function () {
            $('#<%=ddlcountry.ClientID%>').change(function () {
                var Country_ID = $('#<%=ddlcountry.ClientID%>').val();
                alert(Country_ID);
            });
        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:DropDownList runat="server" ID="ddlcountry">
                <asp:ListItem Value="0">--Select--</asp:ListItem>
                <asp:ListItem Value="1">India</asp:ListItem>
                <asp:ListItem Value="2">US</asp:ListItem>
                <asp:ListItem Value="3">UK</asp:ListItem>
            </asp:DropDownList>
        </div>
    </form>
</body>

</html>

Jquery Onchange Event with HTML DropDown

<html>
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script>
        $(document).ready(function () {
            $('#ddlcountry').change(function () {
                var Country_ID = $('#ddlcountry').val();
                alert(Country_ID);
            });
        });
    </script>

</head>
<body>
    <form>
        <div>
            <select id="ddlcountry">
                <option value="0">--Select--</option>
                <option value="1">India</option>
                <option value="2">US</option>
                <option value="3">UK</option>
            </select>
        </div>
    </form>
</body>
</html>

Note:
1. Always Call Asp.net Control ID like this $('#<%=ddlcountry.ClientID%>').
2. Call HTML Control ID Like this $('#ddlcountry')

Also Read:


Textbox onchange jquery



I hope you like this "change event in jquery for dropdown". If you have any question feel free to comment below.


Read More