ASP.NET blog by Subgurim

Some things about ASP.NET, C#, ASP.NET AJAX, javascript...
Comunactivo

 I love SEO :D

 That's the reason I'm participating in a Spanish contest of SEO, which goal is to positionate the word "comunactivo" on www.google.es.

The Web on first position on December 15 at 12:00 am will be the winner.

 So, if you want to help me, please link to http://comunactivo.subgurim.net/ with the anchor "comunactivo".

Posted: Nov 10 2008, 07:23 PM by subgurim | with 1 comment(s)
Filed under: , ,
GoogleMaps.Subgurim.NET 3.0 just released

The GoogleMaps.Subgurim.NET 3.0 version brings us a lot of improvements, news features and bugs correction.
It is, probably, the most important change made since this Google Maps control for ASP.NET was born. There is a list with the most important changes:

Improvements

  • Important: GMap_Width and GMap_Height are no longer available. Instead we will use width and Height.
  • New map view: the raised map or Physical Map.
  • Complete GoogleEarth, Sky, Mars y Moon maps support.
  • Added two new fields to GAjaxServerEventArgs: zoom y map type.
  • New property: GAdsManager.
  • Improved the GoogleBar with GoogleBarOptions.
  • serverEvents improved with ajaxUpdateProgressMessage.
  • New GoogleMaps parallel control: Static Map.
  • New controls for choosing between the map types: GHierarchicalMapTypeControl and MenuMapTypeControl .
  • Bools "geodesic" y "clickable" added to polylines , and bool "clickable" added to polygons
  • Properties viewport y baseCountryCode added to geoCoding for both client and server: .
  • The server geoCoding has a new option, "output" (to choose between xml, klm, json and csv, or return the GeoCode class).
  • Better support for GeoCoding errors.
  • Added new elements to the Datasource:
    • Polygons and Polylines
    • Icons.
  • A very popular request: TileLayers and Custom Maps.
  • Server events with ASP.NET Postback.
  • New class: Store, to store data and share it between Javascript, clientEvents, serverEvents and server.
  • Street View support with GStreetViewOverlay and GStreetViewPanorama.
  • Added the GMaps Utility Library elements.
  • New code minimization options (enablePostBackPersistence, enableGetGMapElementsById).
  • GScreenOverlay similar to GGroundOverlay)
  • New extrabuiltControl: NumericalZoomControl
  • Multilingual support for the map.
AntiSpam HttpModule

I hate the Spam robots, and they hate me. I also hate captchas... so, how can I avoid that they write garbage on my websites?

This HttpModule, with three (1+2) basic rules (the last is optional) has been the solution:

using System;
using System.Web;

namespace Subgurim.Tools
{
    public class AntiSpamModule : IHttpModule
    {
        public void Init(HttpApplication app)
        {
            app.BeginRequest += new EventHandler(AntiSpamFilter);
        }

        private void AntiSpamFilter(object sender, EventArgs e)
        {
            HttpResponse response = ((HttpApplication)sender).Response;
            HttpRequest request = ((HttpApplication)sender).Request;

            // 1.- They are sending a  POST
            // 2.- The call doesn't provide from any other page
            // 3.- The call provides from another page but it's not on my domain.
            if ((request.Form.Count > 0) &&
                    ((request.UrlReferrer == null) ||
                    (!request.UrlReferrer.Authority.Equals(request.Url.Authority, StringComparison.InvariantCultureIgnoreCase))))
            {
                try
                {
                    response.End();
                }
                catch (System.Threading.ThreadAbortException ex)
                {
                    // No hacer nada
                }
            }
        }

        public void Dispose()
        {
        }
    }
}

Configure the HttpModule inside the system.web of your web.config and that's all.

    <system.web>
        <httpModules>
            <add name="AntiSpamModule" type="Subgurim.Tools.AntiSpamModule"/>
        </httpModules>
    </system.web>

Ajax UrlTester

Yesterday I have done a javascript that calls a list of urls and returns its Status and Status Code. It uses XMLHttpRequest not ASP.NET AJAX :D

It's an easy .ascx control so you can easyly use and change it.

You can configure the pages that you want to test with code like this:

        AjaxPageTester1.UrlList.Add("/default.aspx");
        AjaxPageTester1.UrlList.Add("/login.aspx");

 

Download the code

Regex Evaluator iGadget

I'm in love with the Google iGadget :D

My last one is a Regular Expressions Evaluator, extremely easy to use and, almost for me, very useful. 

If you use Regular Expressions give it a try ;)

You can install it clicking here

ClickOnce Button

Working in one of my applications, I needed a button that disables when it were clicked.

 So I have been working on it and here is the final code.

 

There are only two Assumptions:

  • The Button must be of type button, no of type submit.
  • The javascript should control if we are working with validator.

 

.aspx

         <asp:TextBox ID="TextBox1" runat="server" ValidationGroup="SubgurimTest"></asp:TextBox>
       
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
            ErrorMessage="*" ControlToValidate="TextBox1" ValidationGroup="SubgurimTest">
        </asp:RequiredFieldValidator>
       
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OnceClickMe" ValidationGroup="SubgurimTest"
            UseSubmitBehavior="false" OnClientClick="clickOnce(this, 'Cargando...')" />
           
        <br />
       
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>

 

.aspx.cs

     protected void Button1_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(1000);
        Label1.Text = DateTime.Now.ToString();
    }

 

.js
         function clickOnce(btn, msg)
        {
            // Test if we are doing a validation
            if (typeof(Page_ClientValidate) == 'function')
            {
                // if we are doing a validation, return if it's false
                if (Page_ClientValidate() == false) { return false; }
            }
           
            // Ensure that the button is not of type "submit"
            if (btn.getAttribute('type') == 'button')
            {
                // The msg attibute is absolutely optional
                // msg will be the text of the button while it's disabled
                if (!msg || (msg='undefined')) { msg = 'Loading...'; }
               
                btn.value = msg;

                // The magic :D
                btn.disabled = true;
            }
           
            return true;
        }


 I wish it can help you

My Netgets on Codeplex

If a Widget is a Web Gadget, a Netget is a dotNET Gadget :P

I'm a Netget fan, I'm always thinking on new user controls, libraries or frameworks, but I have not time enough to work on them as I wanted...

Therefore I've decided to make some of my favorite Netgets OpenSource on Codeplex

I'm talking about:
- FileUpload AJAX.
- Chat.
- Sitemap Generator.
- Multisearch API.

 
Any kind of contributions are welcome, so if you're a developer and you like any of this projects feel free to contact me to become a developer :D

To be or not to be... a frame...
I am in charge of www.todoexpertos.com, one of the most important Spanish Websites, with millions of unique visitors per month.

I don't know why, maybe for a future phising attack, but there were 3 other sites that put mine inside a frame... of course without permission.

As you can imagine, their code was similar to this one:

<HTML>
<HEAD></HEAD>
<FRAMESET>
  <FRAME src="http://www.todoexpertos.com">
</FRAMESET>
</HTML>


So their site seems to be todoexpertos.com... so I could be angry, or apply this easy javascript code that assures that your web is not inside an iframe:

if (top.location!=self.location) top.location=self.location;

With only one line of code you save headaches :D
Posted: Oct 08 2007, 05:24 PM by subgurim | with no comments
Filed under:
Google Maps Control for ASP.NET

You will be probably in agreement with me if I say that the Google Maps API is one of the most powerful API's on the WWW. I'll really like it, because it allows to make really good geo-applications that a time ago you could not nor be raised.

I began to work with it in may of last year (2006), and then "the question comes"... why not to do an ASP .NET Control that generates the Google Maps API Code?

Now, one year and four months later my Google Maps control has been downloaded more than 7000 times (and growing) and translated to 9 languages by the community (English, Castellano, Français, Nederlands, Svenska, Italiano, Polski, Deutsch, Português brasileiro), and waiting for the turkish translation. Does anybody want to help with the Chinese, Japonese, Hindi, Arabian, Portuguese, Russian or any other language translation? :D

The control  is very simple to use, and on the site you'll found a complete "How to..." section, a "Code Gallery" and an "Icon Gallery". It's not only a Google Maps API parser, but also has other extra features as Server Events, inverse Geocoding, extra controls, etc.

The control is absolutely free, but the community animated me to offer licences to be sure that the project won't die. This licences are extremely cheap, and the only thing they do is remove the HTML comments of the control, so on commercial applications no references to the site of the control will appear. No other limitations are applied.

So take a look at the Google Maps for ASP.NET control site, and please give me your opinion about it :D

 

 


My first ASP.NET weblogs post :)

Firstly, I must thank Joe his invitation to write at the ASP.NET weblogs.

Until now, I only wrote in Spanish at my Spanish ASP.NET Blog (Google say’s that it’s one of the most popular), but I’m not afraid with writing on both languages, although my English is simple and far from perfect.

 

What I am going to write in this Blog?

Well, I’m obviously going to write some technical articles of ASP.NET, JavaScript, ASP.NET AJAX and C#, but I’ll also write about the external libraries and controls that I use, and others that I’ve created.

 

I wait you here.

 

Posted: Oct 02 2007, 05:56 PM by subgurim | with 6 comment(s) |
Filed under:
More Posts