Good evening Kranthi
There are many options to do this. You can use validation controls , they use Javascript to do this and i once wrote an article regarding them here
http://www.dotnetfunda.com/articles/article785-how-to-use-validation-controls-in-aspnet-.aspx or you can look at this example i prepared, this will be a rough example i quickly prepared before i go to sleep(Midnight in South Africa now)
Normally you will have a javascript in the head of your page written for your asp.net textboxes like this
<script type="text/javascript">
function GetElemets() {
var text1 = document.getElementById('<%=TextBox1.ClientID%>').value;
var text2 = document.getElementById('<%=TextBox2.ClientID%>').value;
var text3 = document.getElementById('<%=TextBox3.ClientID%>').value;
var text4 = document.getElementById('<%=TextBox4.ClientID%>').value;
var text5 = document.getElementById('<%=TextBox5.ClientID%>').value;
var text6 = document.getElementById('<%=TextBox5.ClientID%>').value;
var text7 = document.getElementById('<%=TextBox7.ClientID%>').value;
if (text1 == "") {
//Give an Error Message
alert("Field missing");
}
if (text2 == "") {
//Give an Error Message
alert("Field missing");
}
if (text3 == "") {
//Give an Error Message
alert("Field missing");
}
if (text4 == "") {
//Give an Error Message
alert("Field missing");
}
if (text5 == "") {
//Give an Error Message
alert("Field missing");
}
if (text6 == "") {
//Give an Error Message
alert("Field missing");
}
if (text7 == "") {
//Give an Error Message
alert("Field missing");
}
}
</script>
and you will have your seven text boxes and button defined like this
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox><br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox><br />
<asp:button ID="Button1" runat="server" OnClientClick="GetElemets ()" />
as you can see i have wired a client site event so that when you click the button the JavaScript will be ran and it will check if there is an empty text box, if yes it will just alert
Thank you for posting at Dotnetfunda
Vuyiswa Maseko
Thank you for posting at Dotnetfunda
[Administrator]
Kranthi, if this helps please login to Mark As Answer. | Alert Moderator