Friday, April 28, 2017

Visual Studio Performance enhancements

If you get the feeling that Visual Studio takes long time for debugging process, ensure that you have made this changes to enhance the performance.

1.Disable XAML Designer (from Options -> XAML Designer -> General -> Enable XAML Designer)

2. Disable Diagnostic Tools while debugging (from Options -> Debugging -> General -> Enable Diagnostic Tools while debugging)

3. Disable full solution analysis  (from  Options -> Text Editor -> C# -> Advanced -> Enable full solution analysis)

Regards
Samitha

Thursday, April 6, 2017

Visual Studio 2015 Installer Projects

If you try to open an Installer project created from Visual Studio 2010 from Visual Studio 2015 you will get a error.

This can be resolved by installing the extension for Visual Studio 2015 which can be downloaded here.

Friday, March 10, 2017

asp.net DropDownList get selected Text and Value

You can use JavaScript or jQuery to get the selected text/value of a fiven dropdownl list as shown below.

HTML
<asp:DropDownList ID="ddlPerson" runat="server"  onchange="GetSelected(this)">
                                                                           

JavaScript

<script type="text/javascript">

    function GetSelectedTextValue(ddl) {
        var selectedText = ddl.options[ddl.selectedIndex].innerHTML;
        var selectedValue = ddl.value;
        alert("Text: " + selectedText + " Value: " + selectedValue);
    }

</script>

jQuery

 <script type="text/javascript">

    $(function () {
        $("#ddlPerson").change(function () {
            var selectedText = $(this).find("option:selected").text();
            var selectedValue = $(this).val();
            alert("Text: " + selectedText + " Value: " + selectedValue);
        });
    });

</script>

Cheers
Samita

Thursday, February 23, 2017

Asp.net Preview Image before Upload

If you want to preview and image before its uploaded you have two options

1. Using a jQuery plugin
  There are plenty of jQuery plugins available that you can use to achieve this purpose. Here I will list some of the common plugins used.

2.Without using a jQuery plugin
  Here you can use simple jQuery as shown below.

HTML

<form id="form1" runat="server">
    <input type='file' id="imgUp" />
    <img id="preview" src="#" alt="your image" />
</form>

JavaScript

<script type="text/javascript">

 $("#imgUp").change(function(){

     var input= $(this).val();


    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#preview').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
});

 </script>

Cheers
Samitha




Friday, February 17, 2017

ASP.Net MVC generate Url of any file

If you want to get generate a URL for a given file (image)  in ASP.net MVC you can use following method

public static string ResolveServerUrl(string serverUrl, bool forceHttps)
{
    if (serverUrl.IndexOf("://") > -1)
        return serverUrl;

    string newUrl = serverUrl;
    Uri originalUri = System.Web.HttpContext.Current.Request.Url;
    newUrl = (forceHttps ? "https" : originalUri.Scheme) +
        "://" + originalUri.Authority + newUrl;
    return newUrl;
} 
 
 Then you can get the absolute URL by calling the method as displayed below.

ResolveServerUrl(VirtualPathUtility.ToAbsolute("~/images/YourImage.gif"),false))
 
 
Refer to this stackflow discussion for more information

 
Cheers,
Samitha
 
 

Friday, February 3, 2017

Printing web pages


When you are developing a Web page, you will have to consider Web page printing facility. There are some guidelines you need to follow to ensure that all the content within the page is printed in a usable way.

Following article discusses on the way you should design the page. In summary you should consider following when designing the style sheet.

1. Design a print style sheet (use media="print")
2. Remove unwanted items (use a no-print class). In addition you might need to eliminate hyperlinks being printed. That can be achieved as shown below.
 @media print
{
     a[href]:after {
    content: none !important;
   }
}

3. Format the page
4. Change the font and Links


Cheers,
Samitha

Friday, January 27, 2017

asp.net mvc disable submit when ENTER key is pressed

When you create a view with a submit button, the default behavior is submit will be triggered on KEY PRESS events.

If your view has a BeginForm, following code will stop submitting on KEY PRESS.

@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { onkeydown = "return event.keyCode!=13" }))
{
    //code
}


Alternatively you can use jQuery to resolve the same issue as follows

<script>

 $(function () {
         $(document).on("keydown", "input", function(e) {
             if (e.which==13) e.preventDefault();
        });
  });

</script>