Jump to content
Xtreme .Net Talk

Moving controls


Recommended Posts

Guest mutant
Posted

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.

  • *Gurus*
Posted

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";
}

Guest mutant
Posted

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.

Guest mutant
Posted

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>

  • *Gurus*
Posted
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.
Guest mutant
Posted

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.

Guest mutant
Posted
Yes, thats what I had like you said before but in my previous post i just mistyped it as ControlID, dont know why :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...