Moving controls dynamically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm working on an web app and I'm interested in moving a TextBox from one
position in the page to another (in the same page) when a user clicks on a
checkbox (i.e. display additional textbox when the user checks "Write more
info"). Is this possible? How hard is it? It's not an html control.
I have asp.net 2.0.

Thanks.
 
Hi,

You could do that with layers and dynamic positioning. When the checkbox is
checked, move the layer and make the textbox multiline.

See the sample code below.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub CheckBox1_CheckedChanged _
(ByVal sender As Object, ByVal e As System.EventArgs)
div1.Style.Item("left") = "200px"
div1.Style.Item("top") = "250px"
div1.Style.Item("height") = "300px"
TextBox1.TextMode = TextBoxMode.MultiLine
TextBox1.Rows = 10

End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Absolute positioning</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="div1" runat="server" style="z-index: 101; left: 8px; width:
100px; position: absolute; top: 43px; height: 100px">
<asp:textbox id="TextBox1" runat="server">Need more
space?</asp:textbox></div>
<asp:checkbox id="CheckBox1" runat="server" autopostback="True"
oncheckedchanged="CheckBox1_CheckedChanged" text="Write more info" /></div>
</form>
</body>
</html>
 
Back
Top