• How to add Twitter Stream to your ASP.NET MVC Website

    by Venkata Koppaka | Oct 24, 2010

    This post will walk you through how to add twitter stream to your ASP.NET MVC Website.

    First go to  http://twitter.com/widgets, then in left side bar under "Widgets for..." select "My Website"

    From the widgets page, choose "Profile Widget" -

    You should end up in a "Customize your Profile Widget" page -

    1. In the settings tab enter your twitter username.
    2. In the preferences tab choose your preferences ideally the number of tweets can be adjusted here.
    3. From the Appearance tab choose the colors of your widget.
    4. From the Dimensions tab choose your Dimensions of the widget.

    Once you are done, hit finish and grab code.

    Copy the script in the textbox.

    Now to integrate it to your ASP.NET MVC Website, Add new MVC Partial View and paste the code from the above step in to your partial view.

    Then simply call Html.RenderPartial and render the Partial View where ever you want.

    Hope this helped,

    Cheers,

    Venkata

    Go comment!
  • Preventing Caching in JQuery Ajax requests

    by Venkata Koppaka | Sep 23, 2010
    To prevent Caching of results while making JQuery Ajax requests use the following code -
    1         <script type="text/javascript"> 
    2             $(function() { 
    3                 $.ajaxSetup({ cache: false }); // prevent caching of get requests (needed for IE). 
    4             }); 
    5         </script> 

    If you use the above script, whenever you make a JQuery ajax request it will auto-add a unique URL parameter to the requestedy url and hence the cached results wont be returned.

    Here is how a JQuery GET request would look like without cache : false


    Here is how JQuery GET request would look like with cache : false.

     

    Hope this helps,

    Cheers,

    Venkata

    Go comment!
  • Using TinyMCE Editor with ASP.NET MVC

    by Venkata Koppaka | Aug 30, 2010

    In this post I will walk through on how to get TinyMCE editor, one of the best WYSIWYG (What YouSee IWhat You Get) editors, to work in a ASP.NET MVC application

    Go to TinyMce website and download the latest Main Package, at the time of writing it is version 3.3.8. Here is a link for direct download  - Click to Download

    I will use a ASP.NET MVC2 App to demonstrate TinyMCE.

    Create a New ASP.NET MVC2 Web Application. Unzip the contents of JScripts folder in TinyMCE zip folder that you downloaded earlier to say /Scripts/Tiny_Mce/

    After you unzip the contents of JScripts folder to your application, your Scripts folder should look something similar to this -

    Include a Script reference of TinyMCE javascript file in your view where you want to use the TinyMCE Editor -

    1 <script src="/Scripts/tiny_mce/tiny_mce.js" type="text/javascript"></script> 

    Then copy the following javascript in to your view to initialize TinyMCE -

    1 <script type="text/javascript"> 
    2         tinyMCE.init({ 
    3             // General options 
    4             mode: "textareas", 
    5             theme: "advanced", 
    6             plugins: "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager", 
    7  
    8             // Theme options 
    9             theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect", 
    10             theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor", 
    11             theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen", 
    12             theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage", 
    13             theme_advanced_toolbar_location: "top", 
    14             theme_advanced_toolbar_align: "left", 
    15             theme_advanced_statusbar_location: "bottom", 
    16             theme_advanced_resizing: true, 
    17  
    18             // Example content CSS (should be your site CSS) 
    19             content_css: "css/example.css", 
    20  
    21             // Drop lists for link/image/media/template dialogs 
    22             template_external_list_url: "js/template_list.js", 
    23             external_link_list_url: "js/link_list.js", 
    24             external_image_list_url: "js/image_list.js", 
    25             media_external_list_url: "js/media_list.js" 
    26  
    27             
    28         }); 
    29     </script> 
    30  
    31  

    You would need a TextArea HTML Control to view TinyMCE editor. Use the following code to add a TextArea to your view.

    1  
    2     <form> 
    3         <textarea name="tinyMCEContent" style="width: 100%"> 
    4         </textarea> 
    5     </form> 

    Run the application, and you should see the TinyMCE Editor like this -

    Hope this helps,

    Cheers,

    Venkata

    Go comment!
  • Shrinking Database Log file

    by Venkata Koppaka | Aug 16, 2010
    To just shrink the size of a database log file, use the following code:
     
    1 backup log database_name with truncate_only 
    2 dbcc shrinkfile (database_log_name) 
    3 GO 

     
    The backup log statement marks all of the transactions listed in the log Inactive, and then the dbcc shrinkfile command will remove the Inactive transactions from the file, thereby shrinking the size of the database.
     
    If the database_log_name is unknown, you can also use the File_ID instead of the name, and that can be found by using:
     
    1 select * from sysfiles 

     
    when you are in the desired database that you want to delete the log from.
     

    There is a shrink database command called dbcc shrinkdatabase (database_name) that takes a database name as an input and will attempt to shrink the size of the database files in the same manor as described above.  

     

    Hope this helps,

    Cheers,

    Venkata


    Go comment!
  • Grey out Submit button after click - ASP.NET

    by Venkata Koppaka | Jul 02, 2010

    This post is small snippet I had to come up with to grey out the submit button after clicking it so the user doesn't click it twice.

    I am using a post in asp.net forums http://forums.asp.net/p/1057086/1868122.aspx as reference.

    The version I am writing here is tailored down version of what the forums website discusses.

    Here is the C# Utility method that generates a script.

    1         ///  <summary> 
    2         /// Generates auto-disable butotn 
    3         /// </summary> 
    4         /// <param name="p">Page Instance</param> 
    5         /// <param name="btn">Button Instance</param> 
    6         /// <param name="disabledText">Text to display on button when clicked</param> 
    7         /// <returns></returns> 
    8         public static string GetLockButtonJscript(Page p, Button btn, string disabledText) 
    9         { 
    10             disabledText = disabledText == "" ? "Processing..." : disabledText; disabledText = disabledText.Replace("'", ""); 
    11  
    12             StringBuilder sb = new StringBuilder(); 
    13             if (btn.CausesValidation && p.Validators.Count > 0 && btn != null) 
    14             { 
    15                 sb.Append("if (typeof(Page_ClientValidate) == 'function') { "); sb.Append("if (Page_ClientValidate('" + btn.ValidationGroup + "') == false) { return false; }} "); 
    16  
    17             } 
    18              
    19             PostBackOptions opt = new PostBackOptions(btn, "", "", false, true, true, true, true, btn.ValidationGroup); 
    20  
    21             sb.Append(p.ClientScript.GetPostBackEventReference(opt)); 
    22             sb.Append(";"); 
    23  
    24             sb.Append("this.disabled='true';this.value='" + disabledText + "';"); 
    25              
    26             return sb.ToString(); 
    27         } 

    To use this method in a .aspx file and disable a button just include this line of code in the Page_Load event -

    1        protected void Page_Load(object sender, EventArgs e) 
    2         { 
    3             btnSubmit.Attributes.Add("onclick", GetLockButtonJscript(this.Page, btnSubmit, "Processing...")); 
    4         } 

    Hope this Helps,

     

    Cheers,

    Venkata


    Go comment!