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 KumarRank #561 · 4.3K reputationPosted Dec 2, 2013, 8:37 PM EST
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>
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Dec 2, 2013, 7:57 PM EST
Sanjay KumarRank #561 · 4.3K reputationPosted Dec 2, 2013, 7:58 PM EST
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/
Vignesh KumarRank #1,578 · 1K reputationPosted Dec 2, 2013, 8:06 PM EST
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">
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Dec 2, 2013, 8:12 PM EST
please share your full page code;
Vignesh KumarRank #1,578 · 1K reputationPosted Dec 2, 2013, 8:33 PM EST
Still the same problem.
Vignesh KumarRank #1,578 · 1K reputationPosted Dec 2, 2013, 8:43 PM EST