Guest mutant Posted May 18, 2003 Posted May 18, 2003 I never really done anything with dynamic controls in ASP.NET so i dont know :) How can I change to location of the control? There isnt any location property or something like that. Quote
*Gurus* Derek Stone Posted May 18, 2003 *Gurus* Posted May 18, 2003 This should be done using CSS and JavaScript. <div id="ctlFoobar" style="position: absolute; top: 100px; left: 100px;">Foobar</div> if (document.all) { //Internet Explorer or other compliant browser document.all.ctlFoobar.style.left = "0px"; } if (document.layers) { //Netscape/Mozilla or other compliant browser document.layers["ctlFoobar"].left = "0px"; } Quote Posting Guidelines
Guest mutant Posted May 18, 2003 Posted May 18, 2003 I tried using HtmlTextWriter to use html, but cant quite get it working. :( I searched here on how to use JavaScript from ASP.NET and this what i came up with. Dim List As New XmlDocument() Dim x As Integer Dim y As Integer Dim scr As String = "<script language='JavaScript'> document.all.Name.style.left = 500 </script>" List.Load(Server.MapPath("List.xml")) Dim NameNodeList As XmlNodeList = List.GetElementsByTagName("Number") Dim node As XmlNode For Each node In NameNodeList Dim Name As New HyperLink() Name.Text = node("Name").InnerXml Name.NavigateUrl = "name.aspx?show=" & node("Name").InnerXml Me.Controls.Add(Name) RegisterClientScriptBlock("movecontrol", scr) Next But it tells me that Name is null. Quote
*Gurus* Derek Stone Posted May 18, 2003 *Gurus* Posted May 18, 2003 Dim scr As String = "<script language='JavaScript'> document.all." & Name.ClientID & ".style.left = 500 </script>" Quote Posting Guidelines
Guest mutant Posted May 18, 2003 Posted May 18, 2003 Is there any reason why ClientID would be empty? I get JavaScript error that identifier is required, the html shows this when debugging that error: <script language='JavaScript'> document.all..style.left = 500 </script> Quote
*Gurus* Derek Stone Posted May 18, 2003 *Gurus* Posted May 18, 2003 You're declaring the Name variable inside a For/Each loop. The variable is most likely out-of-scope when the code is attempting to access it. Client IDs are automatically assigned to controls, so the possibility of it being null is slim to nill. Quote Posting Guidelines
Guest mutant Posted May 18, 2003 Posted May 18, 2003 I had to move the scr string declaratin to the loop too, because it was using Name.ControlID before the control was declared. I also tried doing this: Dim Name As HyperLink 'above the loop and Name = New HyperLink 'in the loop I also tried to do in without any loops, and it still gave the same error. Quote
*Gurus* Derek Stone Posted May 18, 2003 *Gurus* Posted May 18, 2003 Dim scr As String = "<script language='JavaScript'> document.all." & [b]Name.ClientID[/b] & ".style.left = 500 </script>" Quote Posting Guidelines
Guest mutant Posted May 18, 2003 Posted May 18, 2003 Yes, thats what I had like you said before but in my previous post i just mistyped it as ControlID, dont know why :) 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.