Hi,
I'm using javascript to validate my form on the client. But have a datagrid which I can add rows to, trouble is when I click the add row button it submits the form and my validation runs, I've got a function to clear the vaildation script but can't work out how to call it before the form submits does anyone have any ideas?
I've tried this but it bombs saying -
Compiler Error Message: BC30456: 'javascript' is not a member of 'ASP.submission_aspx'.
<asp:button id="cmdAddAuthor" runat="server" CausesValidation="False" OnClick="javascript:frmvalidator.clearAllValidations();" Text="Add"></asp:button>
The crux of the problem is how to call a javascript function before submit to the server for a specific button?
Cheers Alin your Page_Load event for the aspx page, try to add code like
cmdAddAuthor.Attributes.Add("onClick", "javascript:frmvalidator.clearAllValidations();")
kleinma,
Thanks, that is spot on, except my function doesn't seem to be working. I changed the javascript to an alert which works so your snippet was perfect.
Me.cmdAddAuthor.Attributes.Add("onClick", "javascript:alert('hello');")
Thanks a bunch
well if your function doesn't seem to be working then the problem lies within the code of clearAllValidations.. but once you get that sorted, everything should be fine ;)
if you want to post the function, I or someone else can try to help
Matt,
Thanks I've managed to get it sorted thanks for your help.
Cheers Al
sounds good.. just to give you a little insight on what is going on, the <asp:button> tag tells the aspx page that its an asp control that will be rendered as an HTML button when the server processes the page and spits HTML out to the browser. this is why you cant just stick your JS inline with the button. The code I provided tells the server to add that HTML to the control when its written out to the browser, hence giving the onclick functionality to the HTML control.
Matt,
Thanks, I appreciate the explanation. I'm still trying to get to grips with this beast. It's been a pretty steep learning curve over the last couple of months, but things are looking up as I'm starting to find that I can answer the occasional post.
Cheers Al
It takes time, but once you get the hang of all the "behind the scenes" stuff (which I am still doing myself, as I only do a little asp.net and mostly windows apps) it really gets easy and it is super powerful for a web development language
Yes, at some point it becomes Tetris-like.
Once you have the basics of the language and the way things work, the rest will start falling in to place. The occasion piece might not seem to fit right, but with time and practice, that happens less and less often.
Friday, March 16, 2012
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment