Problem in using "Button1.Attributes.Add " for client side script for Validations

A

Anup

In my form I and doing validations using 'Javascript' as I m using
ASP1.1 and there is very less support for Validators there.


//Code Behind
private void Page_Load(object sender, System.EventArgs e)
{
Button1.Attributes.Add("OnClick","fun()");
}
Problem in using "Button1.Attributes.Add " for client side script for
Validations

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("Hello, World");
}


//Client Side Script

<script language="javascript">

function fun()
{
if (document.Form1.TextBox1.value != '')
{
alert("Hello");
return true;
}
else
{
alert("World")
return false;
}
}

</script>


What I need to do is, if TextBox1 is Empty, Response.Write("Hello,
World") should not get executed, i.e. The Code written in Button should
not be executed.

What Should I do??

Thanks and Regards
Anup
 
A

Anup

OK,
I got the problem,

Code should be like :-
Button1.Attributes.Add("OnClick","return fun()");


and not like:-
Button1.Attributes.Add("OnClick","fun()");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top