i have set textbox's auto postback = true and add the following code but still failed. why?
Protected Sub txt_keyword_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_keyword.TextChanged
Me.RadioButton2.Checked = True
End Sub
kengkit
Member
120 Points
244 Posts
set radiobutton is checked while textbox is focus
Apr 13, 2012 05:28 PM|LINK
hi all,
i have set textbox's auto postback = true and add the following code but still failed. why?
Protected Sub txt_keyword_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_keyword.TextChanged Me.RadioButton2.Checked = True End Subrobwscott
Star
8079 Points
1491 Posts
Re: set radiobutton is checked while textbox is focus
Apr 13, 2012 05:39 PM|LINK
much easier w/ jquery =)
$('#<%=txt_keyword.ClientID%>').keyup( function () { if ($(this).not(':empty')) { $('#<%=RadioButton2.ClientID').attr('checked','checked'); } else { $('#<%=RadioButton2.ClientID').removeAttr('checked'); } });or - you can use "blur" instead of "keyup" also
$('#<%=txt_keyword.ClientID%>').keyup( function () { if(!$.trim(this.value).length) { $('#<%=RadioButton2.ClientID').attr('checked','checked'); } else { $('#<%=RadioButton2.ClientID').removeAttr('checked'); } });Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
kengkit
Member
120 Points
244 Posts
Re: set radiobutton is checked while textbox is focus
Apr 13, 2012 06:29 PM|LINK
robwscott
Star
8079 Points
1491 Posts
Re: set radiobutton is checked while textbox is focus
Apr 13, 2012 06:35 PM|LINK
download the jquery library
http://jquery.com/
add the javascript in your head
<head>
// drag the file in here
</head>
put this at before your ending tags
<script type="text/javascript">
$(document).ready( function () {
// put that code in here
});
</script>
</form>
</body>
</html>
Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
kengkit
Member
120 Points
244 Posts
Re: set radiobutton is checked while textbox is focus
Apr 14, 2012 03:19 AM|LINK
Hi sir,
I have got an error:
Parser Error Message: The server block is not well formed.
$('#<%=RadioButton2.ClientID').attr('checked','checked');Please advice. Hundred Thanks & Happy Weekend to you :)
ZeeshanAnsar...
Participant
878 Points
264 Posts
Re: set radiobutton is checked while textbox is focus
Apr 14, 2012 04:13 AM|LINK
try with following code it is working.
<head runat="server"> <title></title> <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script language="javascript"> function callme() { $('#<%= RadioButton1.ClientID %>').attr('checked', 'checked'); } $(document).ready(function () { $('#txt').focus(); }); </script> </head> <body> <form id="form1" runat="server"> <div> </div> <asp:RadioButton ID="RadioButton1" runat="server" /> <br /> <asp:TextBox ID="txt" TabIndex="1" ClientIDMode="Static" runat="server" /> <br /> <asp:TextBox ID="txt1" TabIndex="2" ClientIDMode="Static" runat="server" onfocus="callme()" /> </form> </body>Please 'Mark as Answer' if this post helps you.
robwscott
Star
8079 Points
1491 Posts
Re: set radiobutton is checked while textbox is focus
Apr 14, 2012 03:43 PM|LINK
my fault i forgot a couple of the "%>" this will work
$('#<%=txt_keyword.ClientID%>').keyup( function () { if ($(this).not(':empty')) { $('#<%=RadioButton2.ClientID%>').attr('checked','checked'); } else { $('#<%=RadioButton2.ClientID%>').removeAttr('checked'); } });or - you can use "blur" instead of "keyup" also
$('#<%=txt_keyword.ClientID%>').keyup( function () { if(!$.trim(this.value).length) { $('#<%=RadioButton2.ClientID%>').attr('checked','checked'); } else { $('#<%=RadioButton2.ClientID%>').removeAttr('checked'); } });Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob