Thursday, August 13, 2009

Ajax Culture Sys.CultureInfo (Ajax em Português)

 

How to change the ajax culture to a new one?

1. Save a copy of MicrosoftAjax.js ( you can find it on System.Web.Extensions thru Reflector tool)

2. Put it in the web server, in my case “/scripts”

3. Duplicate the file and rename it to MicrosoftAjax.PT-pt.js

4. Edit the file MicrosoftAjax.PT-pt.js and do some replace of strings (ex: month names)

5. Edit the ScriptManager (The value “PT-pt” from the ResourcesUICultures attribute is used to get the MicrosoftAjax.PT-pt.js)

<asp:ScriptManager ID="ScriptManager" runat="server" EnableScriptLocalization="true" EnableScriptGlobalization="true">
<Scripts>
    <asp:ScriptReference Name="MicrosoftAjax.js" Path="~/Scripts/MicrosoftAjax.js" ResourceUICultures="PT-pt" />
</Scripts>
</asp:ScriptManager>

 

Ref: http://msdn.microsoft.com/en-us/magazine/cc135974.aspx

and http://msdn.microsoft.com/pt-br/magazine/cc135974.aspx

You are done.

Wednesday, August 12, 2009

Use Custom Objects in Project Settings

 

1.Add a new setting, set the name and one of displayed types.

2.Inside your VS.Net open the Settings with the Xml Editor.

3.Locate your new setting:

<Setting Name="ReplaceSomething" Type="System.String" Scope="Application">
        <Value Profile="(Default)">            
        </Value>
    </Setting>

 

4.Edit the Type attribute in my case, i changed to:

<Setting Name="ReplaceSomething" Type="RegExHttpModule.RegExReplaceRule" Scope="Application">
        <Value Profile="(Default)">            
        </Value>
    </Setting>

5.And now place the Xml Serialization version of the object:

<Setting Name="ReplaceSomething" Type="RegExHttpModule.RegExReplaceRule" Scope="Application">
        <Value Profile="(Default)">           
            &lt;RegExReplaceRule xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
            &lt;UrlRegularEx&gt;1&lt;/UrlRegularEx&gt;
            &lt;FileContentRegularEx&gt;2&lt;/FileContentRegularEx&gt;
            &lt;FileContentReplace&gt;3&lt;/FileContentReplace&gt;
            &lt;/RegExReplaceRule&gt;
        </Value>
    </Setting>

6.Now you can close de Xml Editor and click over the Settings file.

Disable multiple postback

How to disable multiple postbacks from a asp.net page (  the easy way, not the best):

1. Use asp.net Button control, check for OnClick and OnClientClick Property

2.OnClientClick you should add a call to the function DisableButtonOnPostBack:

<asp:Button ID="Button1" runat="server" OnClientClick="return Navigate();" onclick="Button1_Click" Text="Button" />

3.And then add the javascript.

<script type="text/javascript">

function DisableButtonOnPostBack()  {

if (!this.disabled) {
              this.disabled = true;
              return true;
          }
          else {
              return false;
          }

}

</script>