Move a <Div> through vb code

G

Guest

Hi,

I have several <Div>'s that I have assigned an ID for. When the page loads
It set the Absolute Position through a Style sheet. Can I then reference the
<Div> through VB to move it to another Absolute. if so can you show me the VB
syntax.

Thanks
 
D

Darrel

I have several <Div>'s that I have assigned an ID for. When the page loads
It set the Absolute Position through a Style sheet. Can I then reference
the
<Div> through VB to move it to another Absolute. if so can you show me the
VB
syntax.

Unless you are writing the CSS via VB and are willing to reload the page to
see the change, then, no. If you want to move the div via client-side
interaction, then you need to use javascript.

-Darrel
 
G

Guest

Reloading is no problem. The Div needs to move as a result of a SQL response.
If I don't use a style sheet and just put the Div in the page can I do it?

Thanks for your quick response!
 
K

Ken Cox - Microsoft MVP

You might be able to use the Panel control for that, since it creates a div.
Here's a little sample that uses a postback to change the position, size and
colour of the panel.

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 Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
If Not IsPostBack Then
pnl1.Attributes.Add _
("style", "z-index: 101; left: 100px; width: 100px;" & _
" position: absolute; top: 100px; height: " & _
"100px;background-color: green;")
End If
End Sub

Protected Sub Button1_Click _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
pnl1.Attributes.Add("style", "z-index: 101; left: 428px;" & _
" width: 100px; position: absolute; top: 112px;" & _
"height: 200px; background-color: yellow;")
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:panel id="pnl1" runat="server" Width="125px" Height="50px"
backcolor="AliceBlue"> </asp:panel>
<br />
<asp:button id="Button1" runat="server" onclick="Button1_Click"
text="Button" /></div>
</form>
</body>
</html>
 
G

Guest

That's perfect!!! Thank you so much. I've been trying to get this worked out
all weekend. I really appreaciate it.

John

Ken Cox - Microsoft MVP said:
You might be able to use the Panel control for that, since it creates a div.
Here's a little sample that uses a postback to change the position, size and
colour of the panel.

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 Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
If Not IsPostBack Then
pnl1.Attributes.Add _
("style", "z-index: 101; left: 100px; width: 100px;" & _
" position: absolute; top: 100px; height: " & _
"100px;background-color: green;")
End If
End Sub

Protected Sub Button1_Click _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
pnl1.Attributes.Add("style", "z-index: 101; left: 428px;" & _
" width: 100px; position: absolute; top: 112px;" & _
"height: 200px; background-color: yellow;")
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:panel id="pnl1" runat="server" Width="125px" Height="50px"
backcolor="AliceBlue"> </asp:panel>
<br />
<asp:button id="Button1" runat="server" onclick="Button1_Click"
text="Button" /></div>
</form>
</body>
</html>


Vear said:
Hi,

I have several <Div>'s that I have assigned an ID for. When the page loads
It set the Absolute Position through a Style sheet. Can I then reference
the
<Div> through VB to move it to another Absolute. if so can you show me the
VB
syntax.

Thanks
 
K

Ken Cox - Microsoft MVP

Thanks for the reply, John... you made my day!

Vear said:
That's perfect!!! Thank you so much. I've been trying to get this worked
out
all weekend. I really appreaciate it.

John

Ken Cox - Microsoft MVP said:
You might be able to use the Panel control for that, since it creates a
div.
Here's a little sample that uses a postback to change the position, size
and
colour of the panel.

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 Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
If Not IsPostBack Then
pnl1.Attributes.Add _
("style", "z-index: 101; left: 100px; width: 100px;" & _
" position: absolute; top: 100px; height: " & _
"100px;background-color: green;")
End If
End Sub

Protected Sub Button1_Click _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
pnl1.Attributes.Add("style", "z-index: 101; left: 428px;" & _
" width: 100px; position: absolute; top: 112px;" & _
"height: 200px; background-color: yellow;")
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:panel id="pnl1" runat="server" Width="125px" Height="50px"
backcolor="AliceBlue"> </asp:panel>
<br />
<asp:button id="Button1" runat="server" onclick="Button1_Click"
text="Button" /></div>
</form>
</body>
</html>


Vear said:
Hi,

I have several <Div>'s that I have assigned an ID for. When the page
loads
It set the Absolute Position through a Style sheet. Can I then
reference
the
<Div> through VB to move it to another Absolute. if so can you show me
the
VB
syntax.

Thanks
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top