European ASP.NET 4.5 Hosting BLOG

BLOG about ASP.NET 4, ASP.NET 4.5 Hosting and Its Technology - Dedicated to European Windows Hosting Customer

ASP.NET Core 1.1 Hosting - HostForLIFE.eu :: How To Change app.config Data in ASP.NET?

clock January 4, 2017 08:20 by author Peter

In this post, I will tell you about How To Change app.config Data in ASP.NET. Please write the following code to change app.config data at runtime.
    private static void SetSetting(string key, string value) 
           { 
               Configuration configuration = 
                   ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
               configuration.AppSettings.Settings[key].Value = value; 
               configuration.Save(ConfigurationSaveMode.Full, true); 
               ConfigurationManager.RefreshSection("appSettings"); 
           } 


The code given below is used to fetch app.config data.
    private static string GetSetting(string key) 
            { 
                return ConfigurationManager.AppSettings[key]; 
            } 


App.config file

Key is lang and value is English.
 
Output

We get the "lang" value as English, this value is fetched from App.config file.

Modify App.config value at runtime.


Code
    public Form1() 
    { 
        InitializeComponent();  
        string objAppConfigValue = GetSetting("lang"); 
        SetSetting("lang", "Tamil"); 
        string objModifiedAppConfigValue = GetSetting("lang"); 
        
    } 

    private static string GetSetting(string key) 
    { 
        return ConfigurationManager.AppSettings[key]; 
    } 

    private static void SetSetting(string key, string value) 
    { 
        Configuration configuration = 
            ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
        configuration.AppSettings.Settings[key].Value = value; 
        configuration.Save(ConfigurationSaveMode.Full, true); 
        ConfigurationManager.RefreshSection("appSettings"); 
    } 



ASP.NET Core 1.1 Hosting - HostForLIFE.eu :: How to Create Circular Progress Bar Dynamically In ASP.NET?

clock December 21, 2016 08:20 by author Peter

In this post, let me explain you about Create Circular Progress Bar Dynamically In ASP.NET. For it, we will take a div and apply style to make it circular.

<div id="circularProgess" class="circularprogress background" runat="server"> 
          <div id="ProgressText" class="overlay" runat="server"></div> 
</div> 


Add the style, mentioned below.
<style> 
    .background { 
        background-image: linear-gradient(<%= Val1 %>, <%= ColorCode %> 50%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0)), linear-gradient(<%= Val2 %>, #AC2D36 50%, #ffffff 50%, #ffffff); 
    } 
 
    /* -------------------------------------
     * Bar container
     * ------------------------------------- */ 
    .circularprogress { 
        float: left; 
        margin-left: 50px; 
        margin-top: 30px; 
        position: relative; 
        width: 180px; 
        height: 180px; 
        border-radius: 50%; 
    } 
 
        /* -------------------------------------
         * Optional centered circle w/text
         * ------------------------------------- */ 
        .circularprogress .overlay { 
            position: absolute; 
            width: 130px; 
            height: 110px; 
            color: white; 
            background-color: #CF5760; 
            border-radius: 50%; 
            margin-left: 25px; 
            margin-top: 23px; 
            text-align: center; 
            line-height: 90px; 
            font-size: 35px; 
            padding-top: 20px; 
        } 
</style> 

In the background style, I have added val1 and val2, where I will assign from .cs page, so we can make a dynamic circular progress bar. Add the properties and methods, mentioned below in .cs file.
private string val1 = "90deg"; 
 
       public string Val1 
       { 
           get { return val1; } 
           set { val1 = value; } 
       } 
 
       private string val2 = "90deg"; 
 
       public string Val2 
       { 
           get { return val2; } 
           set { val2 = value; } 
       } 
 
       private string colorCode = "#ffffff"; 
 
       public string ColorCode 
       { 
           get { return colorCode; } 
           set { colorCode = value; } 
       } 
 
       protected void Page_Load(object sender, EventArgs e) 
       { 
           ProgressText.InnerText = "0%"; 
           CalculateActiveUsersAngle(75); 
       } 
 
       private void CalculateActiveUsersAngle(int TotalUser) 
       { 
           //int TotalUser = 50; 
 
           if (TotalUser == 0) 
           { 
               Val2 = "90deg"; 
               Val1 = "90deg"; 
               ColorCode = "#ffffff"; 
           } 
           else if (TotalUser < 50 && TotalUser > 0) 
           { 
               double percentageOfWholeAngle = 360 * (Convert.ToDouble(TotalUser) / 100); 
               Val2 = (90 + percentageOfWholeAngle).ToString() + "deg"; 
               Val1 = "90deg"; 
               ColorCode = "#ffffff"; 
           } 
           else if (TotalUser > 50 && TotalUser < 100) 
           { 
               double percentage = 360 * (Convert.ToDouble(TotalUser) / 100); 
               Val1 = (percentage - 270).ToString() + "deg"; 
               Val2 = "270deg"; 
               ColorCode = "#AC2D36"; 
           } 
           else if (TotalUser == 50) 
           { 
               Val1 = "-90deg"; 
               Val2 = "270deg"; 
               ColorCode = "#AC2D36"; 
           } 
           else if (TotalUser >= 100) 
           { 
               Val1 = "90deg"; 
               Val2 = "270deg"; 
               ColorCode = "#AC2D36"; 
           } 
 
           ProgressText.InnerText = TotalUser + "%"; 
 
       } 


CalculateActiveUsersAngle() method will calculate and show the exact angle .You can assign the angle if you want to CalculateActiveUsersAngle() method. For this example, I have assigned 75, so circular progress will display 75% on the radial. And here is the output:

HostForLIFE.eu ASP.NET Core 1.1 Hosting

European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



ASP.NET Core 1.1 Hosting - HostForLIFE.eu :: How to Get IP Address In ASP.NET?

clock December 14, 2016 08:07 by author Peter

In this post, I will tell you how to Get IP Address In ASP.NET. An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication. An IP address serves two principal functions: host or network interface identification and location addressing. Its role has been characterized as follows: "A name indicates what we seek. An address indicates where it is. A route indicates how to get there.”

There are two versions of IP address, earlier Version of IP address is IPv4 contains IP address as 32 bit number, and then because of growth of internet new version of IP is developed named IPv6 which takes 128 bit to store the IP Address.

There are different ways to get IP Address of visitor of the websites.

First method of getting IP Address is using “HTTP_X_FORWARDED_FOR” and “REMOTE_ADDR”. Where, “X_FORWARDED_FOR” is HTTP header field for identifying originating IP Address of the client who connected to internet and “REMOTE_ADDR” Returns the IP address of the remote machine.

Code to get IP Address using Method 1:

Second method of getting IP address is using built in functionality of ASP.NET. Here we use Request property of Page Class which gets the object of HttpRequest class for the requested page. HttpRequest is sealed class which enables ASP.NET to read the HTTP values sent by client machine during the web request. We access the UserHostAddress property of HttpRequest class to get the IP Address of the visitor.

Code to get IP Address using Method 2:

Default.aspx

Call above both method in Page_Load event, as soon as page will load you will get output like this.

HostForLIFE.eu ASP.NET Core 1.1 Hosting

European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



ASP.NET Core 1.1 Hosting - HostForLIFE.eu :: Using Highchart In ASP.NET

clock December 8, 2016 08:56 by author Peter

In this post, will tell you how to use Highchart in ASP.NET. Highchart in ASP.NET is purely a JavaScript and jQuery based API which can create interactive charts for representing the data. Highchart is a client-side API and it is flexible for use on different kinds of web browsers.

And here is the feature of highchart:

  • Compatible: Highchart works on all kinds of browsers.
  • Highchart is free for non-commercial purposes.
  • Different types of charts are available.
  • We can easily integrate it with .NET.

Types of Charts

Highcharts support different types of charts, such as:

  • Gauges
  • Basic Area chart
  • Bar chart
  • Column chart
  • Line chart
  • Pie chart
  • Polar chart
  • Range series

How it works

  • Download this dll and add to your project:
  • Download and add JavaScript to your project:
  • Chart Creation
  • Chart Output

Step 1

  • Download this dll to add to your project or install NET Highcharts.
  • You can follow the below steps.

Step 2
Download Highcharts and add reference of the JavaScript in your page or master page:
Add the below script
        <script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script> 
        <script src="../../Scripts/highcharts.js" type="text/javascript"></script> 

Step 3

Chart Creation

Below code 
        for Mvc 
        public ActionResult Index() { 
                DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart").SetXAxis(new XAxis { 
                        Categories = new [] { 
                            "Jan", 
                            "Feb", 
                            "Mar", 
                            "Apr", 
                            "May", 
                            "Jun", 
                            "Jul", 
                            "Aug", 
                            "Sep", 
                            "Oct", 
                            "Nov", 
                            Dec " }  
                        }).SetSeries(new Series { 
                        Data = new Data(new object[] { 
                            29.9, 
                            71.5, 
                            106.4, 
                            129.2, 
                            144.0, 
                            176.0, 
                            135.6, 
                            148.5, 
                            216.4, 
                            .1, 
                            95.6, 
                            54.4 
                        }) 
                    }); 
                    return View(chart); 
                } 
                Below Code 
                for Asp.net 
                protected void Page_Load(object sender, EventArgs e) { 
                    DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart").SetXAxis(new XAxis { 
                        Categories = new [] { 
                            "Jan", 
                            "Feb", 
                            "Mar", 
                            "Apr", 
                            "May", 
                            "Jun", 
                            "Jul", 
                            "Aug", 
                            "Sep", 
                            "Oct", 
                            "Nov", 
                            "Dec" 
                        } 
                    }).SetSeries(new Series { 
                        Data = new Data(new object[] { 
                            29.9, 
                            71.5, 
                            106.4, 
                            129.2, 
                            144.0, 
                            176.0, 
                            135.6, 
                            148.5, 
                            216.4, 
                            194.1, 
                            95.6, 
                            54.4 
                        }) 
                    }); 
                    ltrChart.Text = chart.ToHtmlString(); 
                } 
    HTML Code
        For Mvc 
        @model DotNet.Highcharts.Highcharts 
        @(Model) 
        For Asp.net < asp: Content ID = "BodyContent" 
        runat = "server" 
        ContentPlaceHolderID = "MainContent" > < asp: Literal ID = "ltrChart" 
        runat = "server" > < /asp:Literal>  < /asp:Content> 


Step 4

We get the output like the below image.

HostForLIFE.eu ASP.NET Core 1.1 Hosting

European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



HostForLIFE.eu Proudly Launches Visual Studio 2017 Hosting

clock December 2, 2016 07:01 by author Peter

European leading web hosting provider, HostForLIFE.eu announces the launch of Visual Studio 2017 Hosting

HostForLIFE.eu was established to cater to an underserved market in the hosting industry; web hosting for customers who want excellent service. HostForLIFE.eu - a cheap, constant uptime, excellent customer service, quality, and also reliable hosting provider in advanced Windows and ASP.NET technology. HostForLIFE.eu proudly announces the availability of the Visual Studio 2017 hosting in their entire servers environment.

The smallest install is just a few hundred megabytes, yet still contains basic code editing support for more than twenty languages along with source code control. Most users will want to install more, and so customer can add one or more 'workloads' that represent common frameworks, languages and platforms - covering everything from .NET desktop development to data science with R, Python and F#.

System administrators can now create an offline layout of Visual Studio that contains all of the content needed to install the product without requiring Internet access. To do so, run the bootstrapper executable associated with the product customer want to make available offline using the --layout [path] switch (e.g. vs_enterprise.exe --layout c:\mylayout). This will download the packages required to install offline. Optionally, customer can specify a locale code for the product languages customer want included (e.g. --lang en-us). If not specified, support for all localized languages will be downloaded.

HostForLIFE.eu hosts its servers in top class data centers that is located in Amsterdam (NL), London (UK), Paris (FR), Frankfurt(DE) and Seattle (US) to guarantee 99.9% network uptime. All data center feature redundancies in network connectivity, power, HVAC, security, and fire suppression. All hosting plans from HostForLIFE.eu include 24×7 support and 30 days money back guarantee. The customers can start hosting their Visual Studio 2017 site on their environment from as just low €3.00/month only.

HostForLIFE.eu is a popular online ASP.NET based hosting service provider catering to those people who face such issues. The company has managed to build a strong client base in a very short period of time. It is known for offering ultra-fast, fully-managed and secured services in the competitive market.

HostForLIFE.eu offers the latest European Visual Studio 2017 hosting installation to all their new and existing customers. The customers can simply deploy their Visual Studio 2017 website via their world-class Control Panel or conventional FTP tool. HostForLIFE.eu is happy to be offering the most up to date Microsoft services and always had a great appreciation for the products that Microsoft offers.

Further information and the full range of features Visual Studio 2017 Hosting can be viewed here http://hostforlife.eu/European-Visual-Studio-2017-Hosting



ASP.NET Core 1.1 Hosting - HostForLIFE.eu :: How to Built-In Logging In .NET Core?

clock November 30, 2016 08:19 by author Peter

In this post, I will show you how to Built-In Logging In .NET Core. For an application, logging is very important to keep track of that application and keep it error-free.

In .NET Core, we don't need any third party logging; instead, we can use built-in logging whenever we want. This is very efficient in terms of code and performance. Now, develope a new .NET Core application and name it.

Step 1: Go to Package mManager View-->Other Windows--> Package manager Console  -->

Install-Package Microsoft.Extensions.Logging

Add Logging
Once  the extension's installed, we can add logging by adding ILogger<T> (custom logging) or ILoggerFactory. If we want to use ILoggerFactory, then we must create it using CreateLogger, to use logging add logging services under ConfigureServices. Moreover, we can use built-in logging with the other loggings (like Nlog) with very minimal code.
services.AddLogging(); 

Startup.cs
public class Startup 
    { 
        public Startup(IHostingEnvironment env) 
        { 
            var builder = new ConfigurationBuilder() 
                .SetBasePath(env.ContentRootPath) 
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) 
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) 
                .AddEnvironmentVariables(); 
            Configuration = builder.Build(); 
        } 
 
        public IConfigurationRoot Configuration { get; } 
 
        // This method gets called by the runtime. Use this method to add services to the container. 
        public void ConfigureServices(IServiceCollection services) 
        { 
            // Add framework services. 
            services.AddMvc(); 
            services.AddLogging(); 
        } 
 
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
        { 
            loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
            loggerFactory.AddDebug(); 
 
            if (env.IsDevelopment()) 
            { 
                app.UseDeveloperExceptionPage(); 
                app.UseBrowserLink(); 
            } 
            else 
            { 
                app.UseExceptionHandler("/Home/Error"); 
            } 
 
            app.UseStaticFiles(); 
 
            app.UseMvc(routes => 
            { 
                routes.MapRoute( 
                    name: "default", 
                    template: "{controller=Home}/{action=Index}/{id?}"); 
            }); 
        } 
    } 

ILoggerFactory: We can use  ILoggerFactory. For this, we must use CreateLogger.

_logger = Mylogger.CreateLogger(typeof(HomeController)); 

HomeController.cs
public class HomeController : Controller 
    { 
        private ILogger _logger; 
 
        public HomeController(ILoggerFactory Mylogger) 
        { 
            _logger = Mylogger.CreateLogger(typeof(HomeController)); 
        } 
 
        public IActionResult Index() 
        { 
            return View(); 
        } 
 
        public IActionResult About() 
        { 
            try 
            { 
                ViewData["Message"] = "Your application description page."; 
                _logger.LogInformation("About Page has been Accessed"); 
                return View(); 
            } 
            catch (System.Exception ex) 
            { 
                _logger.LogError("About: " + ex.Message); 
                throw; 
            } 
        } 
 
        public IActionResult Contact() 
        { 
            try 
            { 
                ViewData["Message"] = "Your contact page."; 
                _logger.LogInformation("Contact Page has been Accessed"); 
                return View(); 
            } 
            catch (System.Exception ex) 
            { 
                _logger.LogError("Contact: " + ex.Message); 
                throw; 
            } 
        } 
 
        public IActionResult Error() 
        { 
            return View(); 
        } 
    } 


Run and Test

LogLevel: We can add logging level by adding the level we want in appsettings.json.Trace

  • Debug
  • Information
  • Warning
  • Error
  • Application failure or crashes         


ASP.NET Core 1.1 Hosting - HostForLIFE.eu :: Uploading File Without PostBack In ASP.NET

clock November 9, 2016 08:55 by author Peter

In this post, you will learn how to upload a file without PostBack in ASP.NET. My main focus to write this blog is that, if you work with file upload control, the page requires full PostBack and if your file upload control is inside the update panel, you must specify your submit button in trigger, as shown below.

 <Triggers> 
    <asp:PostBackTrigger ControlID=""/> 
 </Triggers> 


This also causes the full PostBack problem. To remove this problem, use "Handler" in ASP. NET C#.

UploadFile.ashx Code

 using System; 
 using System.Web; 
 using System.IO; 
 using System.Web.SessionState; 
 public class UploadFile: IHttpHandler, IRequiresSessionState { 
     public void ProcessRequest(HttpContext context) { 
         string filedata = string.Empty; 
         if (context.Request.Files.Count > 0) { 
             HttpFileCollection files = context.Request.Files; 
             for (int i = 0; i < files.Count; i++) { 
                 HttpPostedFile file = files[i]; 
                 if (Path.GetExtension(file.FileName).ToLower() != ".jpg" && 
                     Path.GetExtension(file.FileName).ToLower() != ".png" && 
                     Path.GetExtension(file.FileName).ToLower() != ".gif" && 
                     Path.GetExtension(file.FileName).ToLower() != ".jpeg" && 
                     Path.GetExtension(file.FileName).ToLower() != ".pdf" 
                 ) { 
                     context.Response.ContentType = "text/plain"; 
                     context.Response.Write("Only jpg, png , gif, .jpeg, .pdf are allowed.!"); 
                     return; 
                 } 
                 decimal size = Math.Round(((decimal) file.ContentLength / (decimal) 1024), 2); 
                 if (size > 2048) { 
                     context.Response.ContentType = "text/plain"; 
                     context.Response.Write("File size should not exceed 2 MB.!"); 
                     return; 
                 } 
                 string fname; 
                 if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE" || HttpContext.Current.Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { 
                     string[] testfiles = file.FileName.Split(new char[] { 
                         '\\' 
                     }); 
                     fname = testfiles[testfiles.Length - 1]; 
                 } else { 
                     fname = file.FileName; 
                 } 
                 //here UploadFile is define my folder name , where files will be store. 
                 string uploaddir = System.Configuration.ConfigurationManager.AppSettings["UploadFile"]; 
                 filedata = Guid.NewGuid() + fname; 
                 fname = Path.Combine(context.Server.MapPath("~/" + uploaddir + "/"), filedata); 
                 file.SaveAs(fname); 
             } 
         } 
         context.Response.ContentType = "text/plain"; 
         context.Response.Write("File Uploaded Successfully:" + filedata + "!"); 
         //if you want to use file path in aspx.cs page , then assign it in to session 
         context.Session["PathImage"] = filedata; 
     } 
     public bool IsReusable { 
         get { 
             return false; 
         } 
     } 
 } 


web.config code

 <?xml version="1.0"?> 
 <!-- 
 For more information on how to configure your ASP.NET application, please visit 
 http://go.microsoft.com/fwlink/?LinkId=169433 
 --> 
 <configuration> 
     <system.web> 
         <compilation debug="true" targetFramework="4.0" /> 
     </system.web> 
     <appSettings> 
         <add key="Upload" value="UploadFile" /> 
     </appSettings> 
 </configuration> 


Default.aspx code

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     <html xmlns="http://www.w3.org/1999/xhtml"> 
  
     <head runat="server"> 
         <title></title> 
         <%-- Should have internet connection for loading this file other wise inherit own js file for supporting js library--%> 
             <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
             <script type="text/javascript"> 
                 function onupload() { 
                     $(function() { 
                         var fileUpload = $('#<%=FileUpload.ClientID%>').get(0); 
                         var files = fileUpload.files; 
                         var test = new FormData(); 
                         for (var i = 0; i < files.length; i++) { 
                             test.append(files[i].name, files[i]); 
                         } 
                         $.ajax({ 
                             url: "UploadFile.ashx", 
                             type: "POST", 
                             contentType: false, 
                             processData: false, 
                             data: test, 
                             success: function(result) { 
                                 if (result.split(':')[0] = "File Uploaded Successfully") { 
                                     document.getElementById("<%=lbl_smsg.ClientID%>").innerText = result.split(':')[0]; 
                                 } else { 
                                     document.getElementById("<%=lbl_emsg.ClientID%>").innerText = result; 
                                 } 
                             }, 
                             error: function(err) { 
                                 alert(err.statusText); 
                             } 
                         }); 
                     }) 
                 } 
             </script> 
     </head> 
  
     <body> 
         <form id="form1" runat="server"> 
             <asp:ScriptManager ID="scmain" runat="server"></asp:ScriptManager> 
             <asp:UpdatePanel ID="upmain" runat="server"> 
                 <ContentTemplate> 
                     <fieldset> 
                         <legend>Upload File WithOut PostBack inside Update Panel</legend> 
                         <asp:FileUpload ID="FileUpload" runat="server" /> 
                         <input type="button" id="btnUpload" value="Upload Files" onclick="onupload();" /> 
                         <asp:Label ID="lbl_emsg" runat="server" ForeColor="Red"></asp:Label> 
                         <asp:Label ID="lbl_smsg" runat="server" ForeColor="Green"></asp:Label> 
                     </fieldset> 
                 </ContentTemplate> 
             </asp:UpdatePanel> 
         </form> 
     </body> 
  
     </html> 


Default.aspx code.cs code

 using System; 
 using System.Collections.Generic; 
 using System.Linq; 
 using System.Web; 
 using System.Web.UI; 
 using System.Web.UI.WebControls; 
 public partial class _Default: System.Web.UI.Page 
 { 
     protected void Page_Load(object sender, EventArgs e) {} 
 } 

HostForLIFE.eu ASP.NET Core 1.1 Hosting

European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



ASP.NET Core 1.0 Hosting - HostForLIFE.eu :: How to Read a Remote WEB Page in ASP.NET C#?

clock October 26, 2016 09:15 by author Peter

In this tutorial, let me show you how to Read a Remote WEB Page in ASP.NET C#. Below is my aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head runat="server"> 
        <title></title> 
    </head> 
    <body> 
        <form id="form1" runat="server"> 
        <div> 
            <asp:Label ID="lblResponse" runat="server"></asp:Label></div> 
        </form> 
    </body> 
    </html> 

Now my aspx.cs is:

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Net; 
    using System.IO; 
     
    public partial class _Default : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            string URLResponse = GetHtmlPage("http://www.google.com"); 
            lblResponse.Text = URLResponse; 
        } 
     
        static string GetHtmlPage(string strURL) 
        { 
     
            String strResult; 
            WebResponse objResponse; 
            WebRequest objRequest = HttpWebRequest.Create(strURL); 
            objResponse = objRequest.GetResponse(); 
            using (StreamReader sr = new StreamReader(objResponse.GetResponseStream())) 
            { 
                strResult = sr.ReadToEnd(); 
                sr.Close(); 
            } 
            return strResult; 
        } 
    } 


Here I am reading http://www.google.com and showing response in a label:

 


HostForLIFE.eu ASP.NET Core 1.0 Hosting

European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



ASP.NET Core 1.0 Hosting - HostForLIFE.eu :: Showing Team Member With Its Team In Gridview Using ASP.NET

clock October 6, 2016 21:38 by author Peter

In this post, i will tell you about Showing Team Member With Its Team In Gridview Using ASP.NET. This following code snippet is for to show team member with its team in Gridview using ASP.NET:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"> 
    <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" /> 
    <HeaderStyle BackColor="#990000" Font-Bold="true" ForeColor="#FFFFCC" /> 
    <AlternatingRowStyle BackColor="#DFDFD0" /> 
    <Columns> 
        <asp:BoundField DataField="Teamname" HeaderText="Teamname" /> 
        <asp:TemplateField HeaderText="Agentname"> 
            <ItemTemplate> 
                <asp:DropDownList ID="ddlagent" runat="server" Width="250px" /> </ItemTemplate> 
        </asp:TemplateField> 
        <asp:TemplateField HeaderText="CountAgent"> 
            <ItemTemplate> 
                <asp:Label ID="lblAgent" runat="server" Width="100px" /> </ItemTemplate> 
        </asp:TemplateField> 
    </Columns> 
    <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" /> 
    <RowStyle BackColor="White" ForeColor="#330099" /> 
    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" /> 
    <SortedAscendingCellStyle BackColor="#FEFCEB" /> 
    <SortedAscendingHeaderStyle BackColor="#AF0101" /> 
    <SortedDescendingCellStyle BackColor="#F6F0C0" /> 
    <SortedDescendingHeaderStyle BackColor="#7E0000" />  
</asp:GridView> 

Code

using System.Data; 
using System.Data.SqlClient; 
using System.Configuration; 
public partial class Default2: System.Web.UI.Page { 
    string ConnStr = ConfigurationManager.ConnectionStrings["CRMConnectionString"].ToString(); 
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CRMConnectionString"].ToString()); 
    DataSet someDataSet = new DataSet(); 
    SqlDataAdapter adapt = new SqlDataAdapter(); 
    protected void Page_Load(object sender, EventArgs e) { 
        TopTeam(); 
    } 
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { 
        if (e.Row.RowType == DataControlRowType.DataRow) { 
            con.Open(); 
            var ddl = (DropDownList) e.Row.FindControl("ddlagent"); 
            var Agent = (Label) e.Row.FindControl("lblAgent"); 
            string TeamName = e.Row.Cells[0].Text.ToString(); 
            SqlCommand cmd = new SqlCommand("SELECT distinct (Agentname +' , ' + Hr_id) as [Agentname] FROM CRM_Agentname " + " WHERE TeamName = '" + TeamName + "' and status='Active'", con); 
            SqlDataAdapter da = new SqlDataAdapter(cmd); 
            DataSet ds = new DataSet(); 
            da.Fill(ds); 
            con.Close(); 
            ddl.DataSource = ds; 
            ddl.DataTextField = "Agentname"; 
            ddl.DataValueField = "Agentname"; 
            ddl.DataBind(); 
            int totalItems = ddl.Items.Count; 
            Agent.Text = totalItems.ToString(); 
        } 
    } 
    private void TopTeam() { 
        con.Open(); 
        SqlCommand cmd = new SqlCommand("SELECT DISTINCT TeamName FROM CRM_Teamname where status='ACtive' and process like 'r%' and teamname!='---- Select ----'", con); 
        SqlDataAdapter da = new SqlDataAdapter(cmd); 
        DataSet ds = new DataSet(); 
        da.Fill(ds); 
        con.Close(); 
        GridView1.DataSource = ds; 
        GridView1.DataBind(); 
        con.Close(); 
    } 
}

HostForLIFE.eu ASP.NET Core 1.0 Hosting

European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



ASP.NET Core 1.0 Hosting - HostForLIFE.eu :: How to Get DropDownList , Value, Index and Text in ASP.NET using JavaScript?

clock September 29, 2016 21:02 by author Peter

In this code snippet, we learn how to get selected value, selected index and selected of asp dropdownlist in JavaScript. First, Create new web application in visual studio.
Now, Add one webform to application. In this tutorial we added WebForm1 in application. And Then Add on DropDownList control to webform. Design webform as follows:

<%@ Page Language="C#" AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs" Inherits="DropDownListJS.WebForm1" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title></title> 
<script type="text/javascript"> 
function GetListDetails() { 
    var param = document.getElementById('ddlColors'); 
    document.getElementById('lblText').innerHTML = param.options[param.selectedIndex].text; 
    document.getElementById('lblValue').innerHTML = param.options[param.selectedIndex].value; 
    document.getElementById('lblIndex').innerHTML = param.options[param.selectedIndex].index; 

</script> 
</head> 
<body> 
<form id="form1" runat="server"> 
<div> 
    <table> 
        <tr> 
            <td> 
                Colors 
            </td> 
            <td> 
                <asp:DropDownList ID="ddlColors" runat="server" onchange="GetListDetails()"> 
                    <asp:ListItem Text="Select" Value="0" /> 
                    <asp:ListItem Text="Red" Value="11" /> 
                    <asp:ListItem Text="Green" Value="22" /> 
                    <asp:ListItem Text="Blue" Value="33" /> 
                </asp:DropDownList> 
            </td> 
        </tr> 
        <tr> 
            <td> 
                Selecte Index :
            </td> 
            <td> 
                <label id="lblIndex">
                </label> 
            </td> 
        </tr> 
        <tr> 
            <td> 
                Selecte Text : 
            </td> 
            <td> 
                <label id="lblText"> 
                </label> 
            </td> 
        </tr> 
        <tr> 
            <td> 
                Selecte Value : 
            </td> 
           <td> 
                <label id="lblValue"> 
                </label> 
            </td> 
        </tr> 
    </table> 
</div>
</form> 
</body> 
</html> 


Next step, Run application.

Finally, Change the color.

HostForLIFE.eu ASP.NET Core 1.0 Hosting

European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



About HostForLIFE

HostForLIFE is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2019 Hosting, ASP.NET 5 Hosting, ASP.NET MVC 6 Hosting and SQL 2019 Hosting.


Month List

Tag cloud

Sign in