Click here to Skip to main content
15,921,660 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear all,

I have a textbox and save button in the footer of my gridview..
I am trying to enter data to the grid through the textbox in the footer of the grid..
I want to write the onclient click event for the save button to avoid the empty text being inserted to the grid..
i would appreciate any help in writing this javascript validation..
Thanks..
Posted
Comments
Sunasara Imdadhusen 3-Nov-10 6:29am    
Provide snippet of code!

Hi Rajesh,


I assumed:
Button Name: btnSave
Textbox Name: txtAdd

Server side code:
C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            btnSave..Attributes.Add("onclick","return checkValidation();");
        }
    } 

Javascript code:
C#
function checkValidation()
{
    var txt = document.getElementById('<%= txtAddlientID %>');
    if(txt.value == '')
    {
        alert('Please enter data before save!');
        return false;
    }
   return true;
}



Please do let me know, if you have any doubt.

Please provide "Vote":thumbsup: if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen
 
Share this answer
 
OnClientClick="return Isnotesempty()";

function Isnotesempty()
{
    if(document.getElementById (objid).value=="")
    {
        alert("Description should not be empty...!");
        document.getElementById (objid).focus();
        return false;
    }
    return true;
}

Happy Coding.
 
Share this answer
 
v2
if txtbox.text != "" then

will execute if the textbox text is not empty
 
Share this answer
 
Comments
Sunasara Imdadhusen 3-Nov-10 6:39am    
You should explain in detail!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900