Not Another WordPress site

From the Blog

ago
18

Eu não gosto de política, assim como muitos brasileiros, e os políticos querem que continuemos assim. O problema de não gosta de política e não se envolver, é que ignorando o que eles estão fazendo com nosso dinheiro acaba indo muito pro bolso deles e acabamos pagando tudo em dobro, saúde, educação e cia, pois pagamos os impostos altos e temos péssimos serviços públicos. Aí tem q pagar escola particular, plano de saúde, etc. etc.
(mais…)

ago
16

I was wondering what to write about, and I realized that I needed to post something about what we have trouble to find the solution. Then I decided to write how to disable a button in a HTML page (using Asp.Net and C#) after the user clicked it. Avoiding so that the user click several times and send several requests to the server.

The solution uses basically javascript to disable the button just after the user clicked it. The method we used lays in a different namespace, called Common, which we pass the button and the text we wish to appear after the user click it (something like “Wait”), as parameters.

The method is bellow:

public static void DisableOnClick(System.Web.UI.WebControls.Button btn, string Message)
{
  string theScript = "";
  if ( btn.CausesValidation )
  {
     theScript = @"
        if (typeof(Page_ClientValidate) == 'function') 
        { 
           if (Page_ClientValidate() == false )
              return false; 
        }";
   }
   theScript += @"
      this.value = '" + Message + @"';
      this.disabled = true;
      document.getElementById('" + btn.ClientID + @"')
.disabled = true;" +
   btn.Page.ClientScript.GetPostBackEventReference(btn, string.Empty) + @";";
            
   btn.Attributes["onclick"] = theScript;
}

Basicaly what the method does is to create a script and attach it at the button click event. This script verify if the button does any kind of validation and, if any, run that code, after it the button is disabled and the new text is setted to the button, then the postback call is made.

Bellow is an example of use:

private void Page_Load(object sender, System.EventArgs e)
{
    Common.DisableOnClick(btnRegister, "Wait...");
}

Simple, easy and usefull…
Enjoy ;)

AJAX Control Toolkit has a control called CalendarExtender.
This control shows a calendar to the user select a date when it clicks a textbox.
Many times we want the user select a future date.

To do that we just need to add the following javascript function:

function checkDate(sender,args)
{
if(sender._selectedDate < new Date())
{
alert(“You need to select a future date!”);
sender._selectedDate = new Date();
// select the current date again
sender._textbox.set_Value(sender._selectedDate.format(sender._format))
}

}

And then you need to add a reference to the javascript funcion in the CalendarExtender, like bellow:


<formid=”form1″ runat=”server”>
<asp:ScriptManager ID=”ScriptManager1″ runat=”server” />
<div>
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
<cc1:CalendarExtender ID=”CalendarExtender1″
runat=”server” OnClientDateSelectionChanged=”checkDate” TargetControlID=”TextBox1″ />
</div>
</form>
ago
10
Posted by Felipe V. Rigo at 10:26 am

Sometimes you just need to redirect the user to a new page. For that purpose you can simply use a PHP script to redirect a user to a different web page.

One reason you may want to do this is that the page they are trying to view changed its location. Using this method, they can be seamlessly transfered to the new page without having to click any link. The main reason to use a PHP script is that it works in all browsers.
(mais…)

ago
10
Posted by Felipe V. Rigo at 10:17 am

Vira e mexe a gente precisa colocar um redirecionamento de uma página para outra. Uma das razões para se querer isso é que talvez a pessoa esteja tentando acessar uma página que não existe ou mudou de lugar.

Existem várias maneiras de se fazer isso, algumas com javascript e cia, porém existe uma maneira infalível de redirecionar que é definindo um header html através do PHP. Usando esse método o usuário será transferido para a nova página de maneira transparente, sem precisar clicar em nenhum link.
(mais…)

jul
03
Posted by Felipe V. Rigo at 3:32 pm

Dicionário: pro.cras.ti.nar – deixar para fazer algo mais tarde.
Wikipedia: Procrastinação é o diferimento ou adiamento de uma ação. Para a pessoa que está procrastinando, isso resulta em stress, sensação de culpa, perda de produtividade e vergonha em relação aos outros, por não cumprir com suas responsabilidades e compromissos. Enquanto é normal que as pessoas procrastinem até um certo ponto, isso se torna um problema quando impede o funcionamento normal das ações. A procrastinação crônica pode ser um sinal de alguma desordem psicológica ou fisiológica.
(mais…)