I’m using linkbuttons in my web applications, my ‘composite controls’ aren’t using ASP Panels (therefore no ‘DefaultButton’ property, not that it would work). My link buttons currently have the href set as ‘javascript:_doPostBack..’ (asp default), but to enable my custom client side validation script, I ALSO have code in an ‘onclick’ attribute.
Typical Button :
<div class="button orange o_lime right Normal">
<a onclick="if (!validateFormmainContent_Login()) return false;"
id="mainContent_Login_ctl09_mainContent_Login_btnSubmit" defaultB="loginForm"
href="javascript:__doPostBack('ctl00$mainContent$Login$ctl09$mainContent_Login_btnSubmit','')">
Submit
</a>
</div>
Typical Form row requiring ‘default button’ action
<div class='row' ID='mainContent_Login_ctl03'>
<label ID='mainContent_Login_ctl04'>Email/Username</label>
<input name="ctl00$mainContent$Login$txtAccount" type="text" id="mainContent_Login_txtAccount" class="lime validate[required]" defaultB="loginForm" />
</div>
My current attempt at code to make this work :
<script type="javascript">
$('input[defaultB]').keypress(function (e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
$('a[defaultB=' + $(e.srcElement).attr('defaultB') + ']').click();
return false;
} else {
return true;
}
});
My current attempted solution assigns a value to ‘defaultB’ with something that matches the ‘defaultB’ value defined in a corresponding button, such that key press ’13’ (enter) should initiate the ‘click’ event. but nothing is happening 🙁
I’ve created a jsfiddle to help, but it isn’t working with stupid ‘cant find function’ exception. 🙁
http://jsfiddle.net/Ninjanoel/yQvKC/
I’d really like to get this working without having to rework all my controls! Can anyone help?
http://jsfiddle.net/Ninjanoel/5WDKT/1/
Is my use of ‘eval’ in this instance dangerous? The use of ‘eval’ on the attributes seems to do the trick for me, but I wonder if it’s too much of a security risk to do it this way?