NW Web Designs

... keeping it simple

11. May 2014 18:30
by Greg
0 Comments

RouteConfig.cs

11. May 2014 18:30 by Greg | 0 Comments

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using System.Web.Routing; 
 
namespace AngularJS_WebApi_EF 
{ 
    public class RouteConfig 
    { 
        public static void RegisterRoutes(RouteCollection routes) 
        { 
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
 
            routes.MapRoute( 
                name: "Default", 
                url: "{controller}/{action}/{id}", 
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
            ); 
        } 
    } 
}

11. May 2014 18:28
by Greg
0 Comments

Route Config

11. May 2014 18:28 by Greg | 0 Comments

   1:  using System; 
   2:  using System.Collections.Generic; 
   3:  using System.Linq; 
   4:  using System.Web; 
   5:  using System.Web.Mvc; 
   6:  using System.Web.Routing; 
   7:   
   8:  namespace AngularJS_WebApi_EF 
   9:  { 
  10:      public class RouteConfig 
  11:      { 
  12:          public static void RegisterRoutes(RouteCollection routes) 
  13:          { 
  14:              routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
  15:   
  16:              routes.MapRoute( 
  17:                  name: "Default", 
  18:                  url: "{controller}/{action}/{id}", 
  19:                  defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
  20:              ); 
  21:          } 
  22:      } 
  23:  }

25. April 2014 06:57
by Greg
0 Comments

JQuery Datepicker and Min-max dates

25. April 2014 06:57 by Greg | 0 Comments

jQuery date picker ... setting a minimum and maximum date.

Set a TextBox with a class of datepick:

<asp:TextBox id="txtDate" runat="server" CssClass="datepick">

</asp:TextBox>

jQuery script in head or footer:

<script type="text/javascript">

$(document).ready(function() {

$('input.datepick');

$.ajax({

type: 'POST',

url: 'ClassTestsAdd.aspx/GetMinDate',

contentType: 'application/json; charset=utf-8',

dataType: 'json',

success: function(data) {

var msg = data;

if (msg.hasOwnProperty('d'))

msg = msg.d;

$('input.datepick').datepicker({

maxDate: '0',

minDate: msg,

onSelect: function() {

$("select[tabindex=" + (this.tabIndex + 1) + "]").focus();

}

});

},

error: function(data) {

$('input.datepick').datepicker({

maxDate: '0',

onSelect: function() {

$("select[tabindex=" + (this.tabIndex + 1) + "]").focus();

}

});

}

});

});

</script>

8. January 2013 23:44
by Greg
0 Comments

Custom Validators in Asp.Net C#

8. January 2013 23:44 by Greg | 0 Comments

Your standard Custom Validator:

 

<asp:CustomValidator ID="cvTimeDiff" ValidationGroup="Custom" runat="server"
Display="Dynamic" ErrorMessage="End time should be greater than Start time"
OnServerValidate="CompareTime"></asp:CustomValidator>

 

The attribute "OnServerValidate" is the client-side part of the validator and is what I use by default.
Its value is the name of the server method used to validate something to true or false.

This is the server side code:

 

   protected void CompareTime(object source, ServerValidateEventArgs args)
      {
          *** Do some validation and return the results as boolean b ***
          args.IsValid = b;
      }



Now your ready to fire the custom validator.

First call the validate method:

    Validate("Custom");


Then check if the page is valid and do something:

   if(Page.IsValid)
   {
    Do something when valid
   }

23. December 2012 07:00
by Greg
0 Comments

There is a duplicate ‘system.web.extensions/scripting/scriptResourceHandler’ section defined

23. December 2012 07:00 by Greg | 0 Comments

Lots of things can cause this error to pop-up, but for me it was something very obscure.  I tried everything I could find on the web … then I actually read the compile error.

CVT1108 : cannot open C:/Windows/TEMP/xxx.tmp for writing

So, I went to the ‘Windows\temp’ folder and checked the permissions, and there it was … make sure that the IIS _IUSRS account has read, write and delete rights on the folder. Some how mine disappeared. After I reset them I was back online. How they disappeared I don’t know, but I have a sneaky idea it was the latest update from Microsoft.

23. December 2012 06:59
by Greg
0 Comments

Bin Deploying ASP.NET MVC-3

23. December 2012 06:59 by Greg | 0 Comments

If your server doesn’t have ASP.NET MVC 3 installed, you’ll need to make sure the following set of assemblies are deployed in the bin folder of your web application:

  • Microsoft.Web.Infrastructure.dll
  • System.Web.Helpers.dll
  • System.Web.Mvc.dll
  • System.Web.Razor.dll
  • System.Web.WebPages.Deployment.dll
  • System.Web.WebPages.dll
  • System.Web.WebPages.Razor.dll

23. December 2012 06:54
by Greg
0 Comments

JQuery Datepicker and Min-max dates

23. December 2012 06:54 by Greg | 0 Comments

jQuery date picker ... setting a minimum and maximum date.

Set a TextBox with a class of datepick:

<asp:TextBox id="txtDate" runat="server" CssClass="datepick">
</asp:TextBox>

jQuery script in head or footer:

<script type="text/javascript">
        $(document).ready(function() {
            $('input.datepick');
            $.ajax({
               type: 'POST',
               url: 'ClassTestsAdd.aspx/GetMinDate',
               contentType: 'application/json; charset=utf-8',
               dataType: 'json',
               success: function(data) {
               var msg = data;
               if (msg.hasOwnProperty('d'))
                msg = msg.d;
               $('input.datepick').datepicker({
               maxDate: '0',
               minDate: msg,
               onSelect: function() {
                  $("select[tabindex=" + (this.tabIndex + 1) + "]").focus();
                 }
                });
               },
               error: function(data) {
               $('input.datepick').datepicker({
               maxDate: '0',
               onSelect: function() {
                 $("select[tabindex=" + (this.tabIndex + 1) + "]").focus();
                }
               });
               }
           });
       });
   </script>

23. December 2012 02:32
by Greg
0 Comments

Ajax call for an Asp.Net page

23. December 2012 02:32 by Greg | 0 Comments

Below is a basic Ajax call using jQuery

 

<script type="text/javascript">
 $(document).ready(function() {

// reset input fields

 $("#btnReset, #btnResetTop").click(function() {
 $('input.test').removeClass('check');
 $(':input', '#aspnetForm')
 .not(':button, :submit, :reset, :hidden')
 .val('')
 .removeAttr('checked')
 .removeAttr('selected');
 $('select').val('0');
 $('input.test').addClass('check');
 $('.errorlabel').html('');
 });

// fire ajax call on blur of textbox

 $('input.check').blur(function() {
 //                alert('in blur');
 var idd = this.id;
 var itt = this.value

 $.ajax({
 type: 'POST',
 url: 'EnterTests.aspx/GetStudent',
 data: '{"it": "' + itt + '"}',
 contentType: 'application/json; charset=utf-8',
 dataType: 'html',
 success: function(data) {
 var msg = eval('(' + data + ')');

 if (msg.hasOwnProperty('d'))
 msg = msg.d;
 if (msg == "error") {
 $("[id$=lblError" + idd.substring(36) + "]").attr('Visible', true);
 $("[id$=lblError" + idd.substring(36) + "]").html('No Record For Student SID');
 }
 else {
 $("[id$=lblError" + idd.substring(36) + "]").attr('Visible', true);
 $("[id$=lblError" + idd.substring(36) + "]").html(msg);
 }
 },
 error: function(XMLHttpRequest, textStatus, errorThrown) {
 alert("An error has happened. Please try again later.");
 }
 });
 });
 });
 Sys.Application.add_init(function() {
 });

 </script>

23. December 2012 02:28
by Greg
0 Comments

Finding row data on button click

23. December 2012 02:28 by Greg | 0 Comments

For some one reason I use this a lot. Seems to be a lot easier then grabbing it off a grid event

 

protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton lnkbtn = (LinkButton)sender;
// command argument from selected row
string id = lnkbtn.CommandArgument;
GridViewRow row = (GridViewRow)lnkbtn.NamingContainer;
// row selected
int gridRow = row.RowIndex;
DataKey key = GridView1.DataKeys[gridRow];
// data key 'Title' from selected row
string k = (string)key["Title"];
Response.Write("title: " + k + ",  Id: " + id);
}