Showing posts with label Web Development. Show all posts
Showing posts with label Web Development. Show all posts

Monday, September 17, 2018

What is Microsoft Doing?

Maybe I'm just old.
Maybe I'm just cranky.
Maybe I'm not that good.

Dealing with Microsoft, to me though, is getting old.  I love C# and many aspects of their web development stack, but I'm tired of all the false starts from Microsoft...


  • Webmatrix->Now kinda "Web Pages" in .net Core
  • MVC vanilla or Core...will vanilla be supported?
  • Web Forms...complicated and code bloat for sure, but instead of abandoning, now when the browsers are finally getting to the point where standard HTML5 is pretty much supported, Microsoft should have enhanced and slimmed down web forms and did them right.
  • Continual configuration nightmares.  Once you figure out a config setting, no big deal, but if you aren't into the art of writing / modifying config files all the time, needing an obscure setting can be pain.
  • Powershell and Unix envy.  Having it is fine, but abandoning GUI tools for it is lame.  I can just use Linux at that point and I would have a more stable OS...
  • IIS...This whole push for Core...is Microsoft going to fix IIS or just get c# to run everywhere?  To me this will translate into MS devs abandoning IIS and using open sourced C#...without attracting to much of the cross stream from the Linux dev crowd to adopt the other direction.  Dumb.  Plus again, if I want to program on Linux, I can already do that.  
  • Visual Studio seems to me to be collapsing on it's own weight.  Creating a simple web project now produces like 500 files with 10 folders and all sorts of again config bull sh*t.  Just to say hello world.  I get tired of the seemingly .5-1.5 gig bi-weekly updates to Visual Studio as well.  Come on guys, get your stuff straight.
  • Entity framework...ambitious idea, I got it to work, but not without it's quirks.  Slow as balls though for high scale apps unless you get in and start tweaking the frack out of things. 
  • Azure...I actually use Azure for home projects, but for professional development I, at least right now, could care little about it.  No way the enterprise stuff I work on is ever going into "the cloud".  So I get worried when I see the latest round of Microsoft Certs all seeming to contain Azure test questions.  I have no problem with Microsoft having a set of Microsoft Azure certs, I mean by all means of course.  But to FORCE Azure knowledge everywhere in order to remain certified pisses me off.
I don't know.  Programming to me seems like a lot of fads for smart people.  Web development is taking data from a user and / or displaying data in a meaningful way with security.  You can make that as complicated or as simple as you want.  It seems like just when web development was becoming fun again (HTML5 stabilizing, not having to write as much separate client code for browser exceptions, lot's of client side frameworks to do animations and such with) my dev stack, Microsoft, exploded.  

Kind of a bummer.  Especially with so many things C# / .Net do right.  Again maybe I'm just getting old and suck, but it seems like with the Microsoft stack lately I struggle with my tools rather than providing solutions.  That bugs me.  I'm looking for something lighter.  I'm not 18 any more where I enjoy jumping over hoop after hoop to get something to work, especially when in the past it seems things were much simpler and easier to get things done.  

I know Waaa right?

I really liked the MVC / SQLite in wal mode on IIS stack.  Though I only used it a few times it worked for me and I was productive in writing quick little web apps.  .Net Core MVC less so. I guess I will explore Core web pages and see if they are light.  I'm also looking at doing somethings in the ancient LAMP stack,maybe just to give me some perspective and possibly provide some backup skills in case Microsoft goes off the deep end.  I'll probably pick up Node again as well.  Ruby?  Naah...Python?  Maybe.




Monday, February 27, 2017

Using the tinyMCE CDN

As you know there are all sorts of text editors out there.  For my purposes tinyMCE works fine.  It has a CDN so with the inclusion of a little javascript, you have a capable wysiwyg text editor without having to install any bits into your code (as long as the CDN is up...).  Here is how I use it.



<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
        <script>
            tinymce.init({
                browser_spellcheck: true,
                contextmenu: false,
                selector: 'textarea',
                height: 500,
                theme: 'modern',
                plugins: [
                  'advlist autolink lists link image charmap print preview hr anchor pagebreak',
                  'searchreplace wordcount visualblocks visualchars code fullscreen',
                  'insertdatetime media nonbreaking save table directionality',
                  'emoticons template paste textcolor colorpicker textpattern imagetools'
                ],
                toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
                toolbar2: 'print preview media | forecolor backcolor emoticons',
                image_advtab: true,
            });
          </script>

This works pretty well as a blog editor.  I have to hand put in some HTML for embedded images and videos, but so far that hasn't been a big issue.  I get the raw HTML from the tinyMCE editor for saving like so-

var ct = tinyMCE.activeEditor.getContent({ format: 'raw' });

Quick and easy.  Happy coding.

Monday, October 10, 2016

CSS Responsive Videos

Again, these are old tricks but new to me as I get back into developing new sites rather than supporting Telerk based ones.  In the previous post I shared a CSS snippet on how to make images responsive.  Now onto video.  A lot of sites offer ways for you to copy some code that allows you to paste their videos into your various web sites.  Many use iframes to do this which can be a little problematic.

The following CSS snippet works for youtube videos at least.  I just take whatever copy/paste code form a given site that allows me to embed things and wrap it in a div with the class "vid".  Here is the CSS.


 .vid {  
   position: relative;  
   padding-bottom: 56.25%;  
   padding-top: 30px;  
   height: 0;  
   overflow: hidden;  
 }  
   .vid iframe, .video-container object, .video-container embed {  
     position: absolute;  
     top: 0;  
     left: 0;  
     width: 100%;  
     height: 100%;  

This seemed to work.  More information [HERE].

Getting the Strong Name PublicKeyTolken from an Assembly

[Update, if this doesn't work check the bottom]


Ok, this is .net 101, but I don't update assemblies that often so here is a recap of it so I remember in the future more for me than for you.

1) First, go the the assembly, right click it, get the details, write down the version number, that is probably old too.

2) Since you have the file open, copy it's path, then open up a Visual Studio command prompt.  Type in

sn -T (paste your path)\yourassemblydll

And it should output a new/correct PublicKeyTolken.

Copy and paste the new version and the new PublicKeyTolken text into your config file.  That should do it.

More info on this [HERE].

---------------------------------------

Well, this used to work all fine and good, but didn't work on a new machine that I have that just had visual Studio 2015 on it.  Here is what I had to do.


1) Navigate with file explorer to where the sn.exe file is located, for me it was here-
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools.  Copy that that path then open the Visual Studio developer prompt.

2) type cd then past the path in, hit enter.

3) Next, get the path to your dll that you want to get a strong name for.  Also write down the detail information like in step 1 in the old way above.

4) In the command prompt type sn.exe -T and hit enter.

That worked for me.

Thursday, October 06, 2016

CSS Responsive Images

This is an old trick but I didn't know it.  Here is how to make your images auto scale-

 img {  
      max-width:100%;  
      height:auto;  
 }  

More [HERE].

Also check out the new picture HTML 5 element [HERE].

Wednesday, August 24, 2016

Telerik and Webforms: Trimming Paste on a RadComboBox

I had an issue with being able to trim incoming text into a radcombobox.  The code below is really simple but it took me a bit to figure out.  I'm stuck not using the latest release of Telerik's ASP.Net webform controls so maybe there is a different way to do this with later versions, but this worked for me.


I'm plugging into the RadComboBox's OnClientItemsRequesting by setting it to "MyItemsRequesting"

  function MyItemsRequesting(s, e) {  
     var txt = e.get_text();  
     if (txt != txt.trim()) {  
      e.set_cancel(true);  
      var d = document.getElementById("mymasternamepageifany" + "_mydropdownid_Input");  
      if (d != null) d.value = txt.trim();  
      s.requestItems(txt.trim(), false);  
     }  
   /* more code */  
  }  



Tuesday, August 02, 2016

Free FTP Program WinSCP

I've used the command line, File Explorer FTP, Smart FTP, Filezilla, and now have settled on the free WinSCP program for FTP type stuff.  It supports ftps and other formats and seems to work pretty well. It is also automatable but I haven't played with that yet.

Check it [HERE].

Visual Studio Image Library

Remember that pack of icons in Visual Studio 2010 that you could use in your projects?  I noticed them missing in Visual Studio 2015.  Apparently in order to save space Microsoft now has them as a download now.  

You can download these icons [HERE].

Friday, November 07, 2014

SQLite Windows and Mono Compatible

I haven't tried this yet, but if you have a .net project that needs to use SQLite on both Mono and Window's platforms, I found this comment interesting.

Taken from here http://www.codeproject.com/Articles/821149/Universal-System-Data-Sqlite-binary-for-NET-and-Mo


You could just use Mono.Data.SQLite PinmemberWilliam Ivanski22-Sep-14 4:16 
I copied the file "Mono.Data.SQLite.dll" from Mono to my application bin folder.

I also copied "sqlite3.dll" from SQLite website.

It works flawlessly under both .NET/Windows and Mono/Linux.

Friday, October 03, 2014

Dates in Javascript and the Underscore Framework

I haven't posted much as I've been busy.  I pan to post a few articles this month, just not sure when I will get to them.  In the meanwhile here is a good article on Javascript dates, which I have to deal with from time to time.

[Link]

Also a framework which might be useful is _underscore.js.  Looks like some useful cross-browser functionality.

[Link]

Thursday, May 29, 2014

A Few SQLite Tips

 
 SQLite http://sqlite.org/ is an open source database that is written in C.  It is similar to say an access .mdb file or a Microsoft SQL Server CE file only databases in that it is a file and runs in the same process (well, some caviots here with newer mods to SQLite but I'm not familiar enough there to comment) as your deployed program.  It is used by Firefox, Chrome, a lot of phone app developers, and now by me.  SQL Server is overkill for many of the little web applications I write and although I like SQL Server Compact Edition it looks like it is dead in the water [LINK].

1) Once you have created a table in SQLite, you cannot add a new column to that table with the alter command that has a default value [LINK].

2) It seems like time for SQLite is defaulted to GMT, which in my opinion is a good thing.  For default dates in tables, use CURRENT_TIMESTAMP.

3) SQLite-Net looks really cool, but I haven't been able to hack it to work for web development.  If you are using Windows 8 and developing APPS or Desktop applications, take a look at it. [LINK].

4) A really great and free GUI manager for SQLite is a plugin for Firefox called SQLite Manager. Look for it in the Firefox Plugins.  More info [LINK].

5) It looks like the main .Net SQLite Data Connection enabler is System.Data.Sqlite.  The full Nuget package contains Linq and Entity Framework support.  More info [LINK].

6) There is a version of SQLite written in managed .net code, but it looks like it is no longer being revised.  Maybe Microsoft will pick it up.  Info [LINK].  You might be able to hack SQLite-net to use this version, as it looks like it was originally intended to use it.  I tried for a few hours but gave up.  Maybe I'll take another stab at it.

7) There are no stored procs with SQLite (although I believe there is a fork in development that supports that, but I'm not sure how stable it is).  You can however create user defined functions.

8) When to use SQLite [LINK].

9) Interestingly, if you try to connect to a SQLite DB that doesn't exist the SQLite Connection object will create a new blank DB file for you with the name that you were looking for.  This actually caused me some confusion as has an extra character in my connection string and suddenly I couldn't query any of my tables...duh, they didn't exist because I was querying a new database.

10) If you are familiar with Transact SQL and Microsoft SQL Server (or MySQL, Postgress, Oracle) I don't think you will have any problems using SQLite.

11) Data types on columns are more recommendations than set and fast.  I believe if you try you can save strings in int fields and mix and match.  This might have changed with the 3.x version but from what I have been reading this at lest used to be very true.  Who knows in some cases this could be a good thing, but in most if you aren't careful this might cause havoc.

12) For bulk inserts you want to use SQLite transactions else SQLite will be very slow [LINK]

13) SQLite select queries are CASE SENSITIVE by default.  You can get around this by using COLLATE NOCASE after your where condition like select * from mytable where colum1 = @somevalue COLLATE NOCASE.  A post explaining the particulars can be found [HERE].

14) There is no "Select top * or Select top 10" in SQLite.  Instead use limit. Example: "Select blah from mytable where blah order by blah limit 10"

I got my start in web development using classic ASP and Access MDB databases.  I could crank stuff out FAST.  I think now for some of my projects using MVC (thought without most of the MVC, just using Razor pages almost like development with WebMatrix) and SQLite might be a sweet spot for me as far as making development fun and productive.  I plan to update this page as I find more little quirks using SQLite with ASP.Net.  I also will be posting some source code examples.

Tuesday, May 27, 2014

Fixing Telerik's RadToolTip After Latest Releases Broke It

Scenario


Ok, so I had the following scenario.  I was using a Telerik Radgrid with a gridtemplate column that displayed user comments.  Often the comments were long so I would truncate the comment text that would be displayed, and then I add a RadToolTip with the target of the comment label in the grid that on hover would display the full comment text in a tool tip.  But then something happened...the latest changes broke the tool tip so that if I did anything on the grid like sort, update a row, whatever often the comment tool tip would become blank.  I read that it has something to do with how the radtooltip now stores it's content in the viewstate...well that was the excuse, but IMHO it is broke as it worked before and it doesn't work now.

The Fix


Step 1) Add a RadToolTipManager to your page, outside of your update pannels.  Here is an example


   <telerik:RadToolTipManager ID="RadToolTipManager1" runat="server" OnAjaxUpdate="RadToolTipManager1_AjaxUpdate"  
    RelativeTo="Element" Position="TopLeft" Width="450" ManualClose="True" ShowDelay="600"  
    Title="Comments">  
   </telerik:RadToolTipManager>  

Notice there is an OnAjaxUpdate method.  You will have to add that in your code behind, but let's worry about that in a second.

Step 2: Add a or update an existing RadGrid ItemDataBound event so we can add a tool tip on to each comment field.


 if ( e.Item.OwnerTableView.Name == "MasterTableName" && ( e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem ) )  
    {  
     Control cntl = e.Item.FindControl ( "mylabelintemplatecontrolidwithtruncatedtext" );  
     if ( cntl != null )  
     {  
      if ( this.RadToolTipManager1 != null )  
      {  
       this.RadToolTipManager1.TargetControls.Add ( cntl.ClientID, true );  
      }  
     }  
    }  

Note: I'm doing the e.Item.OwnerTableView.Name check because I'm using a grid with detail tables. If you don't have any detail tables you can skip that part of the check.  You might also add in a check to make sure the Radgrid is in read only mode, I didn't but I might go back and do that just to make it more efficient.

Step 3) Add your RadToolTipManager Ajax update method.


   protected void RadToolTipManager1_AjaxUpdate ( object sender, Telerik.Web.UI.ToolTipUpdateEventArgs e )  
   {  
    for ( int i = 0 ; i < MyGridView.Items.Count ; i++ )  
    {  
     if ( MyGridView.Items[ i ].OwnerTableView.Name == "MasterTableName" && ( MyGridView.Items[ i ].ItemType == GridItemType.Item || MyGridView.Items[ i ].ItemType == GridItemType.AlternatingItem ) )  
     {  
      /* unfortunately only get client ID back on ajax method, so we have to loop to find matching client ID */  
      Control cntl = MyGridView.Items[ i ].FindControl ( "mylabelintemplatecontrolidwithtruncatedtext" );  
      if ( cntl != null && cntl.ClientID == e.TargetControlID )  
      {  
       /* get row ID number */  
       int myID = Convert.ToInt32(MyGridView.Items[ i ].GetDataKeyValue ( "myID" ));  
        /* now get full comment text out of the database */  
        var rv = ( from myrow in ( (DataView)MyDataSet.Select ( DataSourceSelectArguments.Empty ) ).ToTable ().AsEnumerable ()  
              where ( myrow.Field<int> ( "myID" ) == myID )  
              select myrow ).FirstOrDefault ();  
       Label lblInsideToolTip = new Label ();  
       lblInsideToolTip.Text = rv[ "mycommenttextfield" ].ToString ();  
       e.UpdatePanel.ContentTemplateContainer.Controls.Add ( lblInsideToolTip );  
      }  
     }  
    }  
   }  

Ok, a few comments on Step 3.  I could only get the ClientID of the target control from the Telerik.Web.UI.ToolTipUpdateEventArgs object, so I had to loop through all of my RadGrid items and then try match client ID's of the column I was looking for.  Kind of a bummer. I elected to grab the comment text from the Dataset itself.  There are other ways of doing this.  Also this is just demo code, you might want to add this in a big try catch or at least check for more nulls.

Conclusion


This seems to work.  I can sort, edit, insert rows and now the comment field's tool tip is always current.  I hope this code helps. Also be sure to add the using System.Linq at the top of the page in your code behind if it isn't there.


Tuesday, May 13, 2014

Web API 2 CRUD Basic Example

Here is a basic Microsoft Web API 2 CRUD example.  The Source code is [HERE] (this gives you the full directory and list of files, just File->Download to download the full zipped project).  I used Visual Studio 2013 and local DB.  I'm not using MVC or any ORM / Entity Framework stuff...this is a very basic example to help get you going.

You will need to change the database path in the web.config file.



Happy Coding!

Tuesday, March 25, 2014

Telerik UI Designer Fix for Asp.Net Ajax

Having trouble with Telerik UI in design mode (btw, I don't usually even look at web form pages in design mode anymore, but some still do).  If you get some weird stuff happening, this might be your fix.

Go to whatever visual studio version you are using and open the visual studio command prompt in admin mode (right click the shortcut, run as administrator...the command prompt might be named something slightly different depending on what version of VS you are using).

Then copy / paste this into the command prompt (changing this slightly for whatever version of the .net framework telerik version your have installed, if you have multiple versions installed do this for each one). Also note depending on what version of the Telerik controls you have installed, you might have to change the "UI for ASP.Net...." path to whatever path your telerik bin lies in.


 gacutil /i "C:\Program Files (x86)\Telerik\UI for ASP.NET AJAX Q1 2014\Bin40\Telerik.Web.Design.dll  

I hope this helps someone, credit goes to my boss for finding this.

Wednesday, March 05, 2014

Web Forms: Radio and Checkbox List Javascript Selection / Checked Manipulation

Yes, I know web forms aren't cool and all the hip kids are using MVC. Some of us are stuck enhancing existing applications (I don't want to call applications that bring in 100's of thousands of dollars "legacy").

Anyway, here is the scenario.  I've got a checkboxlist control.  I also have a radiobuttonlist with two entries, "All" and "None".  When I click on the radiobuttonlist I want to either check all the items in the checkboxlist control or uncheck all the items in the checkboxlist control.  I also wanted the checkboxlist control set so once individual items are checked the two options in the radiolistbuttonlist to be deselected / unchecked. I'm using Telerik controls so I can use a limited subset of jQuery, so I used it.

Step 1: Code Behind

On my page load I did this-

     ListItem lst1 = new ListItem ( Classes.Utility.Translate ( "AllLabel" ), "A" );  
     ListItem lst2 = new ListItem ( Classes.Utility.Translate ( "NoneLabel" ), "N" );  
     lst1.Attributes.Add ( "onclick", "SetClear(true)" );  
     lst2.Attributes.Add ( "onclick", "SetClear(false)" );  
     rdoOptions.Items.Add ( lst1 );  
     rdoOptions.Items.Add ( lst2 );  
     chkList.Attributes.Add ( "onclick", "return ClearRadioButtonList()" );  

The translate stuff don't worry about.  Just the way I do translation on the fly (for another post).  Note if you set the onclick event for each item or for all items by setting the onclick for the control rather than the items.

Step 2: Client Side

Here are a few Javascript functions I added-

  function ClearRadioButtonList() {  
     $("#<%= rdoOptions.ClientID %> input[type=radio]").prop('checked', false);  
    }  
    function SetClear(b) {  
     $("#<%= chkList.ClientID %> input[type=checkbox]").prop('checked', b);  
    }  

And it works!  I hope this helps someone.  These two pages were helpful to me figuring this out-

https://stackoverflow.com/questions/12482532/clear-radiobutton-list-selection-using-jquery
http://forums.asp.net/p/1303486/2549201.aspx


Wednesday, February 26, 2014

Web Forms: Getting the Bound DataRow Values of a Grid Row While in Read Only Mode

OK, I had a Telerik gridview, and I wanted to add a right click event on the rows that would pop a window.  I also wanted to pass some of the data elements on the row clicked in the URL string of the popup window.

On the MasterTableView I had the Primary Key ID in the DataKeyNames property, so I could get the primary key ID from the clicked row using this technique-

http://www.telerik.com/forums/how-to-create-dynamic-context-menu-in-hierarchy-grid

But what about the rest of the data?  I could try to get at the data in it's label form on the grid row, but what I really wanted was the underlying data that was bound to the grid.  After tweaking a using a little bit if Linq, I came up with this-


  protected void GridContextMenu_ItemClick ( object sender, RadMenuEventArgs e )  
   {  
    try  
    {  
     string radGridClickedRowIndex = Request.Form[ "radGridClickedRowIndex" ]; //hidden form field  
     int RowIndex = -1;  
     RowIndex = Convert.ToInt32 ( radGridClickedRowIndex );  
     GridDataItem gridRow = GridView.Items[ RowIndex ] as GridDataItem;  
     int ID = Convert.ToInt32(gridRow.GetDataKeyValue ( "ID" ).ToString ());  
     var rv = ( from myrow in ((DataView)GRIDDataSet.Select ( DataSourceSelectArguments.Empty )).ToTable().AsEnumerable ()  
           where ( myrow.Field<int> ( "ID" ) == ID )  
           select myrow ).FirstOrDefault ();  
      ...  

And then you can access items in the bound data row like this

string myvalue = rv["column_name"].ToString();


Some of you will not get what I'm talking about.  But to a certain group of people I hope this is useful. Remember to include the System.Linq namespaces at the top of the code behind page.

Wednesday, January 22, 2014

Avoid Common CSS Problems

Here is a useful link in avoiding common CSS problems when you are creating CSS from scratch.

Problems addressed are pushing your footer to the bottom and padding issues.  Basic but if you aren't in CSS everyday but when you are you like to start from scratch this is useful.

http://helabs.com.br/blog/2014/01/21/prevent-common-problems-when-writing-css-from-scratch/

Friday, January 03, 2014

45 Useful Javascript Tips

Flippin' Awesome has compiled a list of 45 useful Javascript tips in one useful spot.  Well worth checking out.

[Link]

Friday, December 27, 2013

Mobile First / Responsive Design Slide Deck

Here is a decent slide deck that talks about mobile first / responsive design.  Worth a look though.

https://app.box.com/s/guafk5lj69sxfy2g6hqr

Source: Matt Duffield

Wednesday, November 13, 2013

Mobile

We all know mobile is the next big thing (has been for about 5 years and just getting bigger).  This slide deck lays it out nicely though if you still have doubts.  Social will be a big part of the mix.


Happy coding.