How can the a client side function be called on a button click event?
In 2.0 Button control has a property OnClientClick which is used to call a client side function before postback. <asp:Button ID='Button1' runat='server' Text='Button' OnClientClick='ClientFunction()'/> <script> functionClientFunction() { alert('ClientFunctionCalled'); } </script>
How can you generate a clock in javascript?
A clock can be generated using the javascript function as given below. <html> <head> <script language='JavaScript'> function startclock() { var thetime=new Date(); var nhours=thetime.getHours(); var nmins=thetime.getMinutes(); var nsecn=thetime.getSeconds(); var nday=thetime.getDay(); var nmonth=thetime.getMonth(); var ntoday=thetime.getDate(); var nyear=thetime.getYear(); var AorP=' '; if (nhours>=12) AorP='P.M.'; else AorP='A.M.'; if (nhours>=13) nhours-=12; if (nhours==0) nhours=12; if (nsecn<10) nsecn='0'+nsecn; if (nmins<10) nmins='0'+nmins; if (nday==0) nday='Sunday'; if (nday==1) nday='Monday'; if (nday==2) nday='Tuesday'; if (nday==3) nday='Wednesday'; if (nday==4) nday='Thursday'; if (nday==5) nday='Friday'; if (nday==6) nday='Saturday'; nmonth+=1; if (nyear<=99) nyear= '19'+nyear; if ((nyear>99) && (nyear<2000)) nyear+=1900; document.clockform.clockspot.value=nhours+': '+nmins+': '+nsecn+' '+AorP+' '+nday+', '+nmonth+'/'+ntoday+'/'+nyear; setTimeout(’startclock()’,1000); } </script> </head> <body> <form name='clockform'> Current Time: <INPUT TYPE='text' name='clockspot' size='40'> </form> <script language='JavaScript'> startclock(); </script> </body> </html>
How can I use a Timer Control to refresh a page automatically at a specified interval
<asp:DropDownList id='DropDownList1' runat='server' onChange='SetClientRefresh(this);'> <asp:ListItem Value='1000'>1 second</asp:ListItem> <asp:ListItem Value='2000'>2 seconds</asp:ListItem> <asp:ListItem Value='3000'>3 seconds</asp:ListItem> </asp:DropDownList> <script language=’javascript’> var cTimeOut = null; function SetClientRefresh(sel) { var newRefresh = sel.options[sel.selectedIndex].value; if (cTimeOut != null) { window.clearTimeout(cTimeOut); } cTimeOut = window.setTimeout('ReLoadPage()', newRefresh); } function ReLoadPage() { window.location.reload(); } </script>
How to pop up a message box when no item in the dropdownlist is selected before postback?
Make sure to add a ListItem with Text=’Please Choose’ and Value =”. Add a RequiredFieldValidator with ControlToValidate= <Dropdownlist1> and Display=’Dynamic’ Add a ValidationSummary with ShowMessageBox =true <asp:DropDownList id='DropDownList1' runat='server'> <asp:ListItem Value=''>Please Choose</asp:ListItem> <asp:ListItem Value='Faq'>Faq</asp:ListItem> <asp:ListItem Value='Tips'>Tips</asp:ListItem> <asp:ListItem Value='Tricks'>Tricks</asp:ListItem> </asp:DropDownList> <asp:RequiredFieldValidator id='RequiredFieldValidator1' style='Z-INDEX: 102; LEFT: 176px; POSITION: absolute; TOP: 48px' runat='server' ErrorMessage='Please Select an Item in the dropdownlist' ControlToValidate='DropDownList1' Display='Dynamic'></asp:RequiredFieldValidator> <asp:Button id='Button1' style='Z-INDEX: 104; LEFT: 128px; POSITION: absolute; TOP: 16px' runat='server' Text='Button'></asp:Button> <asp:ValidationSummary id='ValidationSummary1' style='Z-INDEX: 105; LEFT: 176px; POSITION: absolute; TOP: 72px' runat='server' ShowMessageBox='True' ShowSummary='False'></asp:ValidationSummary>
How can I make a Textbox a mandatory field if a checkbox is checked on a button click event in the client side?
<asp:TextBox id='TextBox1' style='Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 104px' runat='server'></asp:TextBox> <asp:CheckBox id='CheckBox1' style='Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 80px' runat='server'></asp:CheckBox> <asp:Button id='Button1' style='Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 144px' runat='server' Text='Button'></asp:Button> <script> function func1() { if(document.getElementById ('CheckBox1').checked == true) { if(document.getElementById('TextBox1').value == '') { alert('Enter something in textbox'); } } } </script> VB.NET Button1.Attributes.Add ('onclick' , 'return func1()'); C# Button1.Attributes.Add ('onclick' , 'return func1()');