hi I have a checkbox and a radiobuttonlist (the radiobuttonlist contains 2 items) in my form. The radiobuttonlist has its visible property set to false at design time. At run time, when the checkbox is checked, then I want the radiobuttonlist to appear. I want
to use javascript. On Form_Load I've done:
function ShowPeriod(w)
{
document.all(w).visible=true;
//document.getElementById("RDLPeriod").style.visibility=true;
}
Upon execution, when I check the checkbox, the code breaks in the script section and tells that : 'document.all(...)' is null or not an object Where is the problem guys ?
If you set visible=false in the server, then the control usually does not render its markup, only ViewState, so then it will not be in the Html. Try doing a "View Source" in your browser and see if it is there. So if it is not, then you will need to set Visible=true
in the server and in the window_onload in client side script, you can make it invisible (style='display:none' or try adding this style with the attribute collection) and then make it visible as your code does.
One of the great advantages of ASP.NET is being able to use postbacks to perform actions instead of relying on javascript. Try handling the chkM.Click event and making the radiobuttonlist visible there. AutoFed
Autofed: The postback is indeed a great advantage but imagine about hundreds of postbacks in the same form... In some cases, I prefer javascript though as it does not do this postback (refresh) of the screen. As CarlosAg rightly pointed out that a server side
control having its visible property set to false is not rendered in the HTML. I just learnt that too. So using the attributes collection I'm trying to hide it but it's not working, can u see any problem: Dim bodyControl As New HtmlGenericControl("body") bodyControl.Attributes.Add("onload",
"javascript:alert('hello');")
You are creating a new body control. This won't help you, since there is already a body "control" explicitly declared. Add an id attribute to the body tag in your aspx page. Then use Page.FindControl(id) to access the body tag, and add the onload attribute
to it. AutoFed
hi there (sorry for the late reply but got stuck in another problem) I gave an id to the body tag and called it bodyID me.FindControl("bodyID").Attributes.Add .... does not work since me.FindControl("bodyID") does not support the Attributes.Add method.... Can
u help?
thanks adec for your reply the code looks ok. I tried something similar in codebehind on page_load:
Dim body As HtmlControl = CType(FindControl("bodyID"), HtmlControl)
body.Attributes.Add("onload", "javascript:alert('hello');")
I'm getting: Object reference not set to an instance of an object Do u think because at that point the body is still being loaded or ... ? what do u propose
?
Frum
Member
130 Points
26 Posts
radiobuttonlist and javascript
Jul 21, 2003 12:28 PM|LINK
chkM.Attributes.Add("onclick", "ShowPeriod('" & RDLPeriod.ClientId & "');return false;")The HTML Source:In the script section I have:function ShowPeriod(w) { document.all(w).visible=true; //document.getElementById("RDLPeriod").style.visibility=true; }Upon execution, when I check the checkbox, the code breaks in the script section and tells that : 'document.all(...)' is null or not an object Where is the problem guys ?CarlosAg
Participant
1355 Points
271 Posts
Microsoft
Re: radiobuttonlist and javascript
Jul 22, 2003 07:58 AM|LINK
autofed
Participant
1789 Points
357 Posts
Re: radiobuttonlist and javascript
Jul 22, 2003 08:01 AM|LINK
Frum
Member
130 Points
26 Posts
Re: radiobuttonlist and javascript
Jul 22, 2003 09:31 AM|LINK
autofed
Participant
1789 Points
357 Posts
Re: radiobuttonlist and javascript
Jul 22, 2003 09:19 PM|LINK
Frum
Member
130 Points
26 Posts
Re: radiobuttonlist and javascript
Aug 01, 2003 10:06 AM|LINK
adec
Star
12495 Points
2491 Posts
Re: radiobuttonlist and javascript
Aug 01, 2003 11:08 AM|LINK
Dim body As HtmlControl = Ctype(FindControl("bodyID", HtmlControl) body.Attributes.Add("[Key]", "[Value]")Andre Colbiornsen
Frum
Member
130 Points
26 Posts
Re: radiobuttonlist and javascript
Aug 01, 2003 11:43 AM|LINK
Dim body As HtmlControl = CType(FindControl("bodyID"), HtmlControl) body.Attributes.Add("onload", "javascript:alert('hello');")I'm getting: Object reference not set to an instance of an object Do u think because at that point the body is still being loaded or ... ? what do u propose ?CarlosAg
Participant
1355 Points
271 Posts
Microsoft
Re: radiobuttonlist and javascript
Aug 01, 2003 07:12 PM|LINK
Frum
Member
130 Points
26 Posts
Re: radiobuttonlist and javascript
Aug 04, 2003 07:41 AM|LINK