Thursday, March 29, 2012
Newbie: JavaScript validation on <Asp:CheckBox click
I am very new to ASP.Net 2, and stuck with a problem.
How can I execute a client side JavaScript function on CheckBox click.
I am able to execute function at server, But I don't know how to validate at
client side before going to server.
This code is within a GridView
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"
Checked='<%# Bind("OpenConnection") %> '
Enabled="True"
OnCheckedChanged="OpenConnection_Clicked" AutoPostBack="True" />
</ItemTemplate>
When I put onClick="Javascript:FunctionName" within the tag, it says:
Validation (ASP.Net): Attribute'onclick' is not a valid attribute for
element 'CheckBox'.
Please help me.
I'll appreciate your help.
Thanks, RobIt looks like button would better suit the purpose - usually when you want t
o
perform an action (as you do with AutoPostBack="true") a button or a link is
the way to go, and you could use OnClientClick property to inject your
javascript
HTH
"Rob" wrote:
> It might be a simple question.
> I am very new to ASP.Net 2, and stuck with a problem.
> How can I execute a client side JavaScript function on CheckBox click.
> I am able to execute function at server, But I don't know how to validate
at
> client side before going to server.
>
> This code is within a GridView
> <ItemTemplate>
> <asp:CheckBox ID="CheckBox1" runat="server"
> Checked='<%# Bind("OpenConnection") %> '
> Enabled="True"
> OnCheckedChanged="OpenConnection_Clicked" AutoPostBack="True" />
> </ItemTemplate>
> When I put onClick="java script:FunctionName" within the tag, it says:
> Validation (ASP.Net): Attribute'onclick' is not a valid attribute for
> element 'CheckBox'.
> Please help me.
> I'll appreciate your help.
> Thanks, Rob
>
>
Newbie: JavaScript validation on <Asp:CheckBox click
I am very new to ASP.Net 2, and stuck with a problem.
How can I execute a client side JavaScript function on CheckBox click.
I am able to execute function at server, But I don't know how to validate at
client side before going to server.
This code is within a GridView
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"
Checked='<%# Bind("OpenConnection") %'
Enabled="True"
OnCheckedChanged="OpenConnection_Clicked" AutoPostBack="True" />
</ItemTemplate>
When I put onClick="javascript:FunctionName" within the tag, it says:
Validation (ASP.Net): Attribute'onclick' is not a valid attribute for
element 'CheckBox'.
Please help me.
I'll appreciate your help.
Thanks, RobIt looks like button would better suit the purpose - usually when you want to
perform an action (as you do with AutoPostBack="true") a button or a link is
the way to go, and you could use OnClientClick property to inject your
javascript
HTH
"Rob" wrote:
Quote:
Originally Posted by
It might be a simple question.
I am very new to ASP.Net 2, and stuck with a problem.
How can I execute a client side JavaScript function on CheckBox click.
I am able to execute function at server, But I don't know how to validate at
client side before going to server.
>
>
This code is within a GridView
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"
Checked='<%# Bind("OpenConnection") %'
Enabled="True"
OnCheckedChanged="OpenConnection_Clicked" AutoPostBack="True" />
</ItemTemplate>
>
When I put onClick="javascript:FunctionName" within the tag, it says:
Validation (ASP.Net): Attribute'onclick' is not a valid attribute for
element 'CheckBox'.
>
Please help me.
I'll appreciate your help.
>
Thanks, Rob
>
>
>
Newbie: Javascript help
user enters a given character (say "?") into a textbox server control please?
Thank youIn the .aspx page (did not check it running):
<head>
...
function checkKey(){
if (window.event.keyCode==63)
myForm.submit();
else
return true;
}
...
</head>
<body>
<form id=myForm ...?>
...
<asp:textbox ... onkeypress="return checkKey();" ... />
...
</form></body
Eliyahu
"MikeH" <MikeH@.community.nospam> wrote in message
news:BE91A000-8D92-448E-9B03-CC531DF85F8D@.microsoft.com...
> What js code is required to automatically submit a page to the server when
a
> user enters a given character (say "?") into a textbox server control
please?
> Thank you
Monday, March 26, 2012
NEWBIE: passing error to javascript alert
is there a way call a javascript function directly from within asp
page?
Example, here is page load event in C#
protected void Page_Load(object sender, EventArgs e){
// create error
int Var0 = 0;
try {
int iVar1 = 8/Var0;
}
catch (Exception ex){
string sExMsg = ex.Message;
//javascript works fine with string constant
Response.Write("<script type='text/javascript'>alert('In Catch');</
script>");
//can write error to page no problem
Response.Write(sExMsg);
// would like a popup with error
Response.Write("<script language='javascript'>doAlert(" + sExMsg +
");</script>");
Response.Write("<script language='javascript'>function doAlert(sExMsg)
{alert(sExMsg);}</script>");
//write error to log since I can't pop-it-up
//StreamWriter sw = File.AppendText(Server.MapPath("~/error.log"));
//sw.WriteLine(sExMsg);
//sw.Close();
}
}
Any help for a newbie is appreciated
Gi<gijeet@.yahoo.comwrote in message
news:1193076186.658316.66870@.e9g2000prf.googlegrou ps.com...
Quote:
Originally Posted by
Any help for a newbie is appreciated
ClientScript.RegisterStartupScript(GetType(), "error", "alert('In Catch');",
true);
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
ClientScript.RegisterStartupScript(GetType(), "error", "alert('In Catch');",
Quote:
Originally Posted by
true);
Thanks but not sure how to use this. Where do I put this? class
level before page load event? within page load? do I need a
RegisterStartupScript for each alert I wish to use?
Gi
<gijeet@.yahoo.comwrote in message
news:1193079485.948563.150590@.i38g2000prf.googlegr oups.com...
Quote:
Originally Posted by
Quote:
Originally Posted by
>ClientScript.RegisterStartupScript(GetType(), "error", "alert('In
>Catch');",
>true);
>
Thanks but not sure how to use this. Where do I put this?
Wherever you like, so long as you don't Redirect from the page...
Basically, it will send down the JavaScript to run after the page had
loaded...
Quote:
Originally Posted by
do I need a RegisterStartupScript for each alert I wish to use?
Yes.
Incidentally, why are you actually doing this...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Incidentally, why are you actually doing this...?
basically for debugging. I don't like response.writes and I'm trying
to learn javascript. but if you know of a better way to popup alerts,
let me know.
use the debugger to debug. alert debugging is asp classic style :)
"gijeet@.yahoo.com" wrote:
Quote:
Originally Posted by
Quote:
Originally Posted by
Incidentally, why are you actually doing this...?
basically for debugging. I don't like response.writes and I'm trying
to learn javascript. but if you know of a better way to popup alerts,
let me know.
>
>
>
>
>
>
This can help you:
How to Pass Messages and Actions between Server and Client
http://usableasp.net/DeveloperPage...erAndClient.htm
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<gijeet@.yahoo.comwrote in message
news:1193076186.658316.66870@.e9g2000prf.googlegrou ps.com...
Quote:
Originally Posted by
Hello,
is there a way call a javascript function directly from within asp
page?
Example, here is page load event in C#
>
protected void Page_Load(object sender, EventArgs e){
>
// create error
int Var0 = 0;
try {
int iVar1 = 8/Var0;
}
>
catch (Exception ex){
>
string sExMsg = ex.Message;
>
>
//javascript works fine with string constant
Response.Write("<script type='text/javascript'>alert('In Catch');</
script>");
>
//can write error to page no problem
Response.Write(sExMsg);
>
// would like a popup with error
Response.Write("<script language='javascript'>doAlert(" + sExMsg +
");</script>");
Response.Write("<script language='javascript'>function doAlert(sExMsg)
{alert(sExMsg);}</script>");
>
//write error to log since I can't pop-it-up
//StreamWriter sw = File.AppendText(Server.MapPath("~/error.log"));
//sw.WriteLine(sExMsg);
//sw.Close();
>
}
>
}
>
Any help for a newbie is appreciated
>
Gi
>
"Eliyahu Goldin" <REMOVEALLCAPITALSeEgGoldDinN@.mMvVpPsS.orgwrote in
message news:%23DynzGXFIHA.4880@.TK2MSFTNGP03.phx.gbl...
Quote:
Originally Posted by
This can help you:
How to Pass Messages and Actions between Server and Client
http://usableasp.net/DeveloperPage...erAndClient.htm
Not much use in this particular case, though, as the OP's requirements for
this were for debugging a la ASP Classic...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net