g_r_a_robinson Posted February 13, 2004 Posted February 13, 2004 Hi I downloaded a 'Dual Select ListBox Control' from the microsoft asp.net component gallery. Great control!! I have one problem. Basically all I need to do is cause a button to become disabled when an item in the 'Dual Select ListBox Control' is selected. It works fine for my other controls including another js control. Heres what I do: DualSelectListBox1.Attributes.Add( "onclick" , "document.getElementById('JobAdder1_Add_Notes_Normal_BTN').disabled=true;document.getElementById('JobAdder1_UpdateJob_BTN').disabled=false;"); I tried contacting the guy who created the control but I don't know if he's still involved with it. I figured their must some other way to activate this control. I went back to scratch and did the following: put the following between <script> tags function doJScript() { alert("My Own JavaScript Alert Box!") } then i tested it using another of my controls, in this case a timepicker: TimePicker1.Attributes.Add( "onclick" , " doJScript();"); Worked fine. But when I do the same with my duallist control DualSelectListBox1.Attributes.Add( "onclick" , " doJScript();"); nothing happens.. This is so important for me and there must be some workaround, any suggestions would be appreciated!! Quote
fadi Posted February 13, 2004 Posted February 13, 2004 u should not put onclick event for the drop down, u should use instead onchange Quote
WebJumper Posted February 13, 2004 Posted February 13, 2004 and mayve the attributes collection of the costumcontrol is not supported, maybe a programming error. look at the generated source code of your browser ans search for your added js-events... Quote
g_r_a_robinson Posted February 13, 2004 Author Posted February 13, 2004 It might be a programming error. I can see the attributes method by intellisense but youre right in that it might not be working. If thats the case is there absolutely any other way that i can cause any click or action to activate or disable another button. Quote
WebJumper Posted February 13, 2004 Posted February 13, 2004 you can add events on the clientside!! javascript function that is called:function jsTestFunction() { if (true) { alert("true"); return true; } else { alert("false"); return false; } } javascript add event to listbox:document.all["DualSelectListBox1"].attachEvent("onchange", jsTestFunction) //note: funtionname without () the events you want to attach can be created at "code-behind"! e.g. string js = "<script language='javascript'>document.all['DualSelectListBox1'].attachEvent('onchange', jsTestFunction)</script>"; Page.RegisterStartupScript(Guid.NewGuid().ToString(), js); Regards, Stefan Quote
g_r_a_robinson Posted February 13, 2004 Author Posted February 13, 2004 question about javascript and asp.net checkbox I have to use some javascript to cause a checkbox when checked to cause another checkbox that is disabled to become enabled. In other words checkbox a checkbox b (disabled) when checkbox a is checked, b becomes enabled. I tried this but it doesn't work, but i think its because its not an onclick thing with the checkbox control but i don't know what it is. Any suggestions would be well appreciated. CheckboxA.Attributes.Add( "onclick" , "document.getElementById('JobAdder1_CheckboxB).disabled=true"); Quote
WebJumper Posted February 13, 2004 Posted February 13, 2004 <HEAD> . . . <script language="javascript"> function jsCheckedChange() { if (document.all["CheckBox1"].checked) { document.all["CheckBox2"].disabled = false; document.all["CheckBox2"].parentElement.disabled = false; } else { document.all["CheckBox2"].disabled = true; document.all["CheckBox2"].parentElement.disabled = true; document.all["CheckBox2"].checked = false; } } </script> </HEAD> . . . <form id="Form1" method="post" runat="server"> <asp:CheckBox id="CheckBox1" runat="server" onclick="jsCheckedChange();"></asp:CheckBox><br> <asp:CheckBox id="CheckBox2" runat="server" Enabled="false"></asp:CheckBox> </form> . . . Quote
g_r_a_robinson Posted February 13, 2004 Author Posted February 13, 2004 thanks for all your help, i'm going to give it a go right now!! Quote
g_r_a_robinson Posted February 14, 2004 Author Posted February 14, 2004 Thanks WebJumper the suggestions worked great. I do have one problem however on the second to last line you submitted <asp:CheckBox id="CheckBox1" runat="server" onclick="jsCheckedChange();"></asp:CheckBox> The compiler gives me an error saying: C:\My Documents\Visual Studio Projects\DuTest\Bak1\WebFiles\modules\JobAdder.ascx(71): Could not find any attribute 'onclick' of element 'CheckBox'. Is there another way? Thanks Quote
WebJumper Posted February 15, 2004 Posted February 15, 2004 you can try this: . . . <script language="javascript"> function jsInit() { document.all["CheckBox1"].attachEvent("onclick", jsCheckedChange) //note: funtionname wirthout () } </script> . . . <body onload="jsInit();"> . . . Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.