Moving controls

  • Thread starter Thread starter mutant
  • Start date Start date
M

mutant

Guest
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.
 
This should be done using CSS and JavaScript.
Code:
<div id="ctlFoobar" style="position: absolute; top: 100px; left: 100px;">Foobar</div>
Code:
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";
}
 
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.

Code:
        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.
 
Code:
Dim scr As String = "<script language=JavaScript> document.all." & Name.ClientID & ".style.left = 500 </script>"
 
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:
Code:
<script language=JavaScript> document.all..style.left = 500 </script>
 
Youre 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.
 
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:
Code:
Dim Name As HyperLink above the loop
and
Code:
Name = New HyperLink in the loop

I also tried to do in without any loops, and it still gave the same error.
 
Code:
Dim scr As String = "<script language=JavaScript> document.all." & [b]Name.ClientID[/b] & ".style.left = 500 </script>"
 
Yes, thats what I had like you said before but in my previous post i just mistyped it as ControlID, dont know why :)
 
Back
Top