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

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

P: n/a
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

Mar 2 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
OK,
I got the problem,

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

Anup wrote:
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


Mar 2 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.