By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,453 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,453 IT Pros & Developers. It's quick & easy.

how to

P: 3
i am having a button and two textfields all are asp.net server controls

on button click,the javascript function has to be called,which checks whether both the textfield's are empty r not

protected void Button1_Click(object sender, EventArgs e)
{
String c, d;
c = TextBox1.Text;
d = TextBox2.Text;
Button1.Attributes.Add("onclick", "validate('c','d')");
if (Page.IsValid == true)
{
Response.Redirect("webform2.aspx");
}

}

function validate(a,b)
{
if(document.getElementById('a').value == "" && document.getElementById('b').value == "")
{
alert("The Fields cannot be empty");
return false
}
else return true
}
wen i click the button wen the text fields are empty it is taking me to the next page... it should'nt happen wat to do
Nov 29 '06 #1
Share this Question
Share on Google+
2 Replies


10K+
P: 13,264
i am having a button and two textfields all are asp.net server controls

on button click,the javascript function has to be called,which checks whether both the textfield's are empty r not

protected void Button1_Click(object sender, EventArgs e)
{
String c, d;
c = TextBox1.Text;
d = TextBox2.Text;
Button1.Attributes.Add("onclick", "validate('c','d')");
if (Page.IsValid == true)
{
Response.Redirect("webform2.aspx");
}

}

function validate(a,b)
{
if(document.getElementById('a').value == "" && document.getElementById('b').value == "")
{
alert("The Fields cannot be empty");
return false
}
else return true
}
wen i click the button wen the text fields are empty it is taking me to the next page... it should'nt happen wat to do
So many things can be the cause here. Now let's start by checking whether the function is getting called at all: change to


[HTML] function validate(a,b) {
alert("Getting called");
if(document.getElementById('a').value == "" && document.getElementById('b').value == "")
{
alert("The Fields cannot be empty");
return false
}
else {
return true;
}
}
[/HTML]
Nov 29 '06 #2

Expert 100+
P: 1,892
Not sure if this matters I didn't test but you may want to use OR to check if those fields are empty.
Nov 29 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.