.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

javascript for field validation on a textbox...

Posted By:      Posted Date: September 13, 2010    Points: 0   Category :ASP.Net
I'm looking at doing the validation for the email in javascript since we have asp.net 1.1. I can get it to just alert fine, but once I add the return validation it doesn't fire. Me.ImageButton2.Attributes.Add("onclick", "return validation(this);") <script language="JavaScript"> <!-- function validation () { var test=""; test = document.ticketForm.emailAddress.value; if (test == "xyz") { alert(test); return false; // validation failed } --> </script>

View Complete Post

More Related Resource Links

How to take value of bound field of grid in a variable or in a textbox.


How to take value of bound field of grid in a variable or in a textbox.

 I m using this code in .aspx page for grid.

<asp:GridView ID="Grd_Mprocess" runat="server" AutoGenerateColumns="False"

                      Width="100%" AllowPaging="True"


                      AllowSorting="True" PageSize="5"  >

                 <RowStyle CssClass="odd" />


<asp:BoundField HeaderText="DOC_TYPE_PK" DataField="DOC_TYPE_PK"  Visible="true" >


  <asp:TemplateField HeaderText="DOC TYPE ID" Visible="true">  &nbs

decimal value validation and round off by javascript

The article decimal value validation and round off by javascript was added by hiral.hapani on Wednesday, June 02, 2010.

Hi All, I have createdone javascript by which you canvalidate a decimal value of any textbox for which you want. By thisjavascriptwecan bind user to enter only digits in textbox. and when he will enter any decimal value javascript will do round off it

Mission Impossible? Use Javascript to Disable a Multi-Line Rich Text Field


Hey Community,

Here's a tough one that I have struggled with and so far have not been able to find an answer for - how do you use Javascript to disable a multi-line rich text field.  I have customized a SP Edit form by adding a CEWP.  In the CEWP I have added the Javascript below (only a partial code sample provided) to disable several fields in the form.  The code works fine for single line text fields but it does not work for multi-line rich text fields.  Any suggestions?

<script language="javascript">
//This runs the function when the form first loads

//This locks the fields the users should not modify
function lockFields()
  var theInputTFTitle = getTagFromIdentifierAndTitle("Input","TextField","Title");
  theInputTFTitle.readOnly = true;
  theInputTFTitle.style.color = 'gray';
  //alert(" Value: " + theInputTFTitle.value);//for testing

   var theInputDDLReplyStatus = getTagFromIdentifierAndTitle("select","DropDownChoice","Reply Status");
  theInputDDLReplyStatus.disabled = true;
  //alert(" Value: " + theInputDDLReplyStatus.value);//for testing

  var theInpu

Asp.net Javascript Validation dd/mm/yyyy format


Hi experts,

 I am trying to validate two textbox (fromdate,todate)

should alert a message when Fromdate is more than Todate

I could find only mm/dd/yyyy format in most of google search.

please give me a script or assist how to do this.



Video: Field and List Item Validation in SharePoint 2010

SharePoint supports the ability to create Excel-like field validation formulas to validate field data in a list, which greatly reduces the amount of custom code that a developer must create and deploy. (Length: 1:44)

How to use server side validation to ensure image field is not null


I'm having trouble accomplishing the above. Below is all the mark up and code. I'm not getting error messages, but the validate image function is not working (fileupload portion is working ok).

In my attempt below---not sure if it's the simplest or best validation approach anyway---the "UserId" parameter appears during rendering to be empty---but in most methods I have it successfully containing or referring to the logged-in user's identification.

Following is the control that refers to the image field (page = advertisement.aspx):

<asp:Image ID="Image" runat="server" ImageUrl ='<%#Eval("UserId","Image.aspx?UserId={0}") %>'


Following is the successful code behind for the page image.aspx referred to above (page = image.aspx.vb):

Partial Public Class Image

    Inherits System.Web.UI.Page

    Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Request.QueryString("UserId") IsNot Nothing Then

            ' Get the connection string from Web.config.

            Using conn As New Sq

Issues with multiline textbox, javascript and IE


Hi All,

i have a requirement to embolden/italicise the selected  text in a textbox. the way it is implemented as is by using a js function which inserts <b> and </b> tags at the start and end of the selected text  for bold, and similarly <i> and </i> tags at the start and end of the selected text  for italics.

here is the code in c# (to add attributes to link buttons)

lkbBold.Attributes.Add("onclick", "AddHTMLTags('" + txtTitle.ClientID + "', 'B'); return false;");
lkbItalic.Attributes.Add("onclick", "AddHTMLTags('" + txtTitle.ClientID + "', 'I'); return false;");

the txtTitle is the id of the text box, which contains the selected text to be emboldend.

and here's the javascript method

function AddHTMLTags(textBoxId, format)
  var textComponent = document.getElementById(textBoxId);
  var selectedText;
  var textToReplace; 
  var content = document.getElementById(textBoxId).value;
  var content1 ;
  var content2 ;
  var newContent; 
      // For IE 
      if (document.selection != undefined)
        var len =  document.selection.createRange().text.length;
        var myrange

How to disable textbox causing validation?

Hello I was running into a strange problem: If I left a textbox blank (in some instances) the textbox would not give up the focus (I could not even close the form).  I learnt later that this was because the text in the textbox was causing validation to fail.  I would have to type in some value (Satisfy validation) before i could close the form. This is problematic for me and I don't want the textbox to behave this way (I do not awnt front end validation).  I desire to have validation done ONLY on the back end.     I thought that I could solve this problem by changing the 'CausesValidation' property in the textbox to false.  This worked!  However it introduced a new problem.  The binding no longer worked on the Textbox.  That is, whatever value I typed in the textbox would not make it to the data set. What is the correct way in solving this problem???  I want validation to be shut off however I still (obviously) need to keep binding in tact...      

Server-side validation on an Entity Framework required field (property) does not work!

Has anyone had issues getting server-side validation on an Entity Framework required field (property) to work? The data type is a string (nvarchar). Server-side validation for required fields of other data types WORK fine. Only string fields have issues. I get the following error on UpdateModel(obj); of my POST method within the controller. Exception Details: System.Data.ConstraintException: This property cannot be set to a  null value.Source Error: Line 4500:                OnTextChanging(value);Line 4501:                ReportPropertyChanging("Text");Line 4502:                _Text = StructuralObject.SetValidValue(value, false);Line 4503:                ReportPropertyChanged("Text");Line 4504:                OnTextChanged(); I've even tried data annotations like this but it seems to get ignored.     [MetadataType(typeof(ObjMD))]     public partial class Obj     {    

Javascript to update value in Textbox

Hi I have a javascript file, which creates a calendar picker. This file is used through out the application and is a piece of code that I have to use because my .Net application is part of another application which uses this piece of JavaScript code.Anyhow, with the calendar picker I can save the date into a textbox, but the problem that I have is the format. Unfortunately, I cannot change the calendar picker code because this will affect other parts of the application. Therefore, what I am looking to do is to reformat the date on the textbox control. This I can do but only when I use the javascript event onfocus.Now, my question is this, is there away in javascript or with jquery that when a value enters into a textbox that this value is then reformatted to the format I want without postback or clicking on the textbox?Thanks

Problem with JavaScript on Textbox

 I have a textbox which is populated by an external javascript file which I cannot alter without affecting another part of the system. What I would like to do is once this textbox has a value to do something with it. The javascript that I want to use is fine, but it won't automatically when a value has populated it i.e. onchange. It will work when the event is onfocus. Is there away in which I can automatically fire off my javascript event when a value has entered the textbox from another piece of javascript code?  

problem with javascript in multiline textbox

 I am setting Maxlength of a textbox using javascript. Take maxlegth as 100.As we know Enter key is taking two char space. But i want to avoid this. i.e. if i press enter key after 96th char it should allow me to enter four more char where now it is allowing only 98. This is wat i am using  function textboxMultilineMaxNumber(txt,maxLen) { try { if(txt.value.length > (maxLen-1)) return false; } } catch(e){ } }

Compare Validation for the Title field of the list

Hi, I do have a field known as 'Title' in the list.My requirement is there should be not be any duplicate values i.e first time if i enter say 'test' in Title field it should save where as second time when i enter same text as 'test' it should show message as 'item already exists with the Title that you have entered'.Ofcourse i should do the compare validation over here but just let me know how to do this Thanks & Regards, Sudheer

linebreak in textbox using javascript

I want to assign a textvalue with linebreaks to a textbox control using javascript.I tried (\n):hlResetStyle.Attributes.Add("onclick", "javascript:document.getElementById('" + CSS.ClientID + "').value='#progress{color:#000;width:500px;height:30px;padding:0px;clear:both;}\n\n\n#progress ul{list-style:none;padding:0px;margin: auto;display:block;}';")and tried (<br/>)hlResetStyle.Attributes.Add("onclick", "javascript:document.getElementById('" + CSS.ClientID + "').value='#progress{color:#000;width:500px;height:30px;padding:0px;clear:both;}<br/><br/><br/><br/>#progress ul{list-style:none;padding:0px;margin: auto;display:block;}';")But without luck....How to do it?

Javascript FromDate to Date Validation Help!

Hi,I want to check fromdate and todate in dd/mm/yyyy.The code below mentioned works perfect for single textbox(fromdate) ,but when tried to do for todate(textbox) it doesnot work properly.From Date Should not be greater than ToDate.Please Help.Below is the code:<html><head><title>Date Example</title><script type="text/javascript">    function isValidDate(sText) {        var reDate = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|20\d{2})/;        return reDate.test(sText);    }    function validate() {        var oInput1 = document.getElementById("txt1");        if (isValidDate(oInput1.value)) {            alert("Valid");        } else {            alert("Invalid!");        }    }</script></head><body>    <P>Date: <input type="

Can I update Project Field value via some javascript?

Hi there, I've a webpart that's designed to update some project field value, this webpart is  located on a Project Details Pages. On this project details page, there is another MS Build-in webpart call Project Field webpart. Now when I clicked the Save ribbon button, the project field webpart will raise some client calls, at the same time my custom webpart will raise a post-back(update value via PSI) call which will kill the client calls..So is it possible for me update the project filed value via some javascript? so I'll no longer raise a postback. Or is it possible for me to capture the client calls event for MS webpart, then I can fired my own PSI code? Thank you,   Regards, Joe

How do i do Validation on a field ?

Team, I have a situation where i need to do validation on a form field. If field A is Yes, Make field B mandidatory(should not be left empty). How can i achieve this? I want to make these changes through sharepoint designer code. Bhadram.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend