TipsOnLips.net

Your .net tips and tricks source

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010


Reset Button The ASP.NET MVC Style

There are many ways to reset a form in MVC including:

  1. Using a Form Reset Button.
  2. Using JavaScript or JQuery to reset a form.

My favorite option is a different one as option 1 only resets input fields and not grids, also it does not work after the form is submitted and the field is bound to a model. Option 2 needs some plumbing for each form.

My favorite option is as below which resets the form without a lot of effort:

 <input  type="button"  class="button"  value="Reset"  name="Reset"  
onclick="document.location.href =' <%  :  Url.Action("YourGetActionMethod")  %>'"  />
 

Categories: .Net Framework | C# | HTML | JavaScript | MVC
Posted by developer on Friday, August 20, 2010 10:44 PM
Permalink | Comments (0) | Post RSSRSS comment feed

C#: Byte Array to Base64 String

         public  static  string  ToBase64String(this  byte [] textBlob)
         {
             System.Text.UTF8Encoding  encoder = new  System.Text.UTF8Encoding ();
             System.Text.Decoder  utf8Decode = encoder.GetDecoder();
 
             int  charCount = utf8Decode.GetCharCount(textBlob, 0, textBlob.Length);
             char [] decoded_char = new  char [charCount];
             utf8Decode.GetChars(textBlob, 0, textBlob.Length, decoded_char, 0);
             string  result = new  String (decoded_char);
             return  result;
         }
 

Categories: C#
Posted by developer on Wednesday, August 18, 2010 1:52 AM
Permalink | Comments (0) | Post RSSRSS comment feed

C#: Convert an ArrayList of strings to a string[] array

To convert an ArrayList to an array of strings, simply do the following:

string[] stringArray = (string[])arrayList.ToArray(typeof(string));

Where arrayList is an ArrayList of strings and stringArray is an array of strings.

 

Source: Click Here


Categories: CSS
Posted by developer on Thursday, August 05, 2010 4:09 AM
Permalink | Comments (0) | Post RSSRSS comment feed

ASP.NET: Url Redirect Action in MVC for a button

1) Action

         public  ActionResult  Publications()
         {
             return  View();
         }

2) Java Script
         <script  type="text/javascript"> 
          $('#btnSubmit').click(function  (e) {
              e.preventDefault();
              location.href = " <%  = Url.Action(" Publications")  %>  " 
              });
        </script> 

3) Html
     <input  type="button"  id="btnSubmit"  class="button"  value="I Agree"  name="Submit"  /> 

Categories: ASP.NET | CSS | JavaScript | MVC
Posted by developer on Wednesday, August 04, 2010 1:57 AM
Permalink | Comments (0) | Post RSSRSS comment feed

ASP.NET: How to return a PDF file in MVC

For a PDF file to be returned as an action response in MVC 2, we have two options:

 1)    Either;

         public  ActionResult  GetMyPdfAsFile()
         {
             return  File(Url.Content("~/Content/Files/PDFs/MyPdf.pdf" ), "application/pdf" );
         }

2)     or;

         public  FileStreamResult  ShowMyPdf()
         {
             string  filePath = Server.MapPath("/Content/Files/PDFs/MyPdf.pdf" );
             byte [] pdf = System.IO.File .ReadAllBytes(filePath);
             MemoryStream  stream = new  MemoryStream (pdf, 0, pdf.Length);
             return  new  FileStreamResult (stream, "application/pdf" );
         }

Categories: ASP.NET | CSS | HTML | MVC
Posted by developer on Tuesday, August 03, 2010 8:25 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Minimum CSS Reset Script

html, body, div, form, fieldset, legend, label{ margin: 0; padding: 0; }
table{ border-collapse: collapse; border-spacing: 0;}
th, td{ text-align: left; vertical-align: top;}
h1, h2, h3, h4, h5, h6, th, td, caption { font-weight:normal; }
img { border: 0; }

Source: Click Here


Tags:
Categories: CSS
Posted by developer on Friday, June 11, 2010 8:17 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Override a background image in CSS

background: none  !important;

This is usefull when you reference an external CSS file and you want to override a background image that you do not like while keeping everything else.


Categories: CSS
Posted by developer on Tuesday, December 29, 2009 8:41 AM
Permalink | Comments (0) | Post RSSRSS comment feed

How to scale the jQuery UI font size for just the UI widgets

Just add (override) this .ui-widget{font-size:11px !important;} in your own style sheet.

Source: Click Here


Categories: CSS | Jquery
Posted by developer on Tuesday, December 15, 2009 4:57 AM
Permalink | Comments (0) | Post RSSRSS comment feed

JQuery UI Themes on Google CDN

      Source: http://blog.jqueryui.com/2009/03/jquery-ui-17/

 


Categories: CSS | Jquery
Posted by developer on Wednesday, December 09, 2009 2:40 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Wrap an li element with an Anchor (link) element using JQuery

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

    <title>Untitled 1</title>

 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>

 

    <script type="text/javascript">

        $(function() {

        var firstLi = $('li:first');

 

        var anchor = '<a href="javascript:void(0)" onclick="myclick(\'' + firstLi.text() + '\')"></a>';

        firstLi.wrap(anchor);

        });

 

        function myclick(test) {

            alert(test);

        }

    </script>

 

</head>

<body>

    <ul id="myUL">

        <li>Dav Letterman</li>

    </ul>

</body>

</html>


Categories: JavaScript | Jquery
Posted by developer on Wednesday, December 09, 2009 1:15 AM
Permalink | Comments (0) | Post RSSRSS comment feed