I am using the below piece of javascript for expty textbox validation on button click. It worked when I placed the script inside head tag. And now it doesn't work as I have placed inside asp:content. Can anyone correct me.
Empty textbox validation on button click
Hi,
I am using the below piece of javascript for expty textbox validation on button click. It worked when I placed the script inside head tag. And now it doesn't work as I have placed inside asp:content. Can anyone correct me.
I am using the below piece of javascript for expty textbox validation on button click. It worked when I placed the script inside head tag. And now it doesn't work as I have placed inside asp:content. Can anyone correct me.
Sanjay KumarPosted Dec 3, 2013, 1:37 AM
try this code
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
function validate() {
if (document.getElementById("<%=txtSearch.ClientID %>").value != "") {
return true;
}
alert('Please enter user details to search!');
return false;
}
script>
asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:TextBox ID="txtSearch" runat="server" Height="20px" Width="150px" />
<asp:ImageButton ID="btnSearchUser" ClientIDMode="Static" ImageUrl="~/SearchButton.png" runat="server" Width="50px" Height="25px" OnClientClick ="javascript:validate()" />
asp:Content>
Vignesh KumarPosted Dec 3, 2013, 1:43 AM
Vignesh KumarPosted Dec 3, 2013, 1:33 AM
Still the same problem.
Sanjeeb LenkaPosted Dec 3, 2013, 1:12 AM
please share your full page code;
Vignesh KumarPosted Dec 3, 2013, 1:06 AM
I placed the script in second content place holder only and still I have problem.
<%@ Page Language="C#" MasterPageFile="~/Menu.Master" AutoEventWireup="true" CodeBehind="Profile.aspx.cs"
Inherits="UI.Profile" %>
User Profile Administration
OnClientClick="return validate()" />
CellPadding="4" OnPageIndexChanging="ResultGridView_PageIndexChanging" OnRowEditing="ResultGridView_RowEditing"
OnRowCancelingEdit="ResultGridView_RowCancelingEdit" PageSize="18" ForeColor="#333333"
GridLines="None">
Sanjay KumarPosted Dec 3, 2013, 12:58 AM
http://www.aspdotnet-suresh.com/2010/10/javascript-validations-to-validate-form.html
http://deepak-sharma.net/2013/08/11/validationsummary-control-in-asp-net/
Sanjeeb LenkaPosted Dec 3, 2013, 12:57 AM