its urgent anyone reply me plz

Posted by Kranthi under ASP.NET on 11/9/2010 | Points: 10 | Views : 803 | Status : [Member] | Replies : 5
I have 7 textbox one search button this search button should be mendatory for atleast one textbox should be entered and this program will write using javascript




Responses

Posted by: Vuyiswamb on: 11/9/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
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

Posted by: Kranthi on: 11/9/2010 [Member] Starter | Points: 25

Up
0
Down
thankyou verymuch sir

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kranthi on: 11/9/2010 [Member] Starter | Points: 25

Up
0
Down
I have 7 textbox one search button this search button should be mendatory for anyone textbox should be entered then only the search result will be displayed and this program will write using javascript



Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 11/10/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
You are welcome

Thank you for posting at Dotnetfunda
[Administrator]

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhuk on: 11/10/2010 [Member] Starter | Points: 25

Up
0
Down
Improvement to Vuyiswa Maseko answer
use this if else block.
if (text1 != "" || text2 != "" || text3 != "" || text4 != "" || text5 != "" || text6 != "" || text7 != "")
{
//Give an Error Message
alert("Your Code");
}
else
{
alert("You need to enter any text");
}
}


Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response