Moving controls dynamically

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.
 
K

Ken Cox [Microsoft MVP]

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
Sean29G025

Latest Threads

Top