Blog

My blog serves as a way for me to post solutions to problems I solve at work or during the long hours of freelance work.


Remove Text from Textbox during OnClick using Razor View

by Ezekiel 7. January 2014 10:49

 

            <div class="editor-field">
                @Html.TextAreaFor(model => model.Product.Description, new
                                {
                                    onfocus="(this.value == 'enter description') && (this.value = '')",
                                    onblur="(this.value == '') && (this.value = 'enter description')"
                                })
                @Html.ValidationMessageFor(model => model.Product.Description)
            </div> 

 

Tags: , ,

Javascript | MVC | Razor Views

JQuery Replace Globally

by Ezekiel 25. November 2012 04:55

 

Use /something/g.

var str = "This is sample text for a sample replace";
str = str.replace(/ /g, "-");

Tags: ,

Javascript | JQuery

Change Control Background Color When Validator Fails

by Ezekiel 30. December 2010 05:43

 

Javascript -

function fnOnUpdateValidators()
{
   for (var i = 0; i < Page_Validators.length; i++)
   {
      var val = Page_Validators[i];
      var ctrl = document.getElementById(val.controltovalidate);
      if (ctrl != null && ctrl.style != null)
      {
         if (!val.isvalid)
            ctrl.style.background = '#FFAAAA';
         else
            ctrl.style.backgroundColor = '';
      }
   }
}

 

Put this in C# Page_Load method  -

Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "val", "fnOnUpdateValidators();");

 

Tags: , , ,

ASP.NET | C# | Javascript

Disable Submit Button When the Submit Button is Clicked

by Ezekiel 12. October 2010 07:14

 

    <script type="text/javascript"><!--
    function doSubmit(btnSubmit) {
        if (typeof(Page_ClientValidate) == 'function' && Page_ClientValidate() == false) {
            return false;
        }   
        btnSubmit.disabled = 'disabled';
        btnSubmit.value = 'Processing. Please wait...';
        <%= ClientScript.GetPostBackEventReference(btnSubmit, string.Empty) %>;   
    }
    //-->
    </script>

 

   <asp:Button ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" OnClientClick="doSubmit(this)" CssClass="submit1" runat="server" />

 

Tags: ,

ASP.NET | Javascript

RecentPosts