Setting physical position of a WebControl from code behind

D

Danijel Valentic

Hi!

I'm very new to programming and asp.net. Can please anyone tell me how to
dynamically move WbControl from code behind?

e.g.: I have a panel and I want to move it on the web form depending on some
events.

Let's say that I want to change control's TOP from 20 to 350(in HTML it
looks like style="... TOP:20px, ...".

Thanks in advanced, d
 
K

Ken Cox [Microsoft MVP]

Hi Danijel,

Just reset the Style parameters based on some event like a button click.
Here's some sample code:

<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 48px; POSITION:
absolute; TOP: 48px" runat="server"
Text="Click Me!"></asp:Button>
<asp:panel id="Panel1" style="Z-INDEX: 102; LEFT: 56px; POSITION:
absolute; TOP: 168px" runat="server"
Width="224px" Height="128px" BackColor="White">
<asp:Image id="Image1" runat="server"
ImageUrl="http://www.gc.ca/images/flag.gif"></asp:Image>
</asp:panel>
</form>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load

End Sub

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Panel1.Attributes.Add("style", _
"Z-INDEX: 102; LEFT: 416px; " & _
"POSITION: absolute; TOP: 56px")
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto
 
D

Danijel Valentic

Hi Ken,

Thanks for your answer, it really helped. I thought it would be something
like that, but I didn't know how to do it. Thans again.


Ken Cox said:
Hi Danijel,

Just reset the Style parameters based on some event like a button click.
Here's some sample code:

<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 48px; POSITION:
absolute; TOP: 48px" runat="server"
Text="Click Me!"></asp:Button>
<asp:panel id="Panel1" style="Z-INDEX: 102; LEFT: 56px; POSITION:
absolute; TOP: 168px" runat="server"
Width="224px" Height="128px" BackColor="White">
<asp:Image id="Image1" runat="server"
ImageUrl="http://www.gc.ca/images/flag.gif"></asp:Image>
</asp:panel>
</form>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load

End Sub

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Panel1.Attributes.Add("style", _
"Z-INDEX: 102; LEFT: 416px; " & _
"POSITION: absolute; TOP: 56px")
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto

Danijel Valentic said:
Hi!

I'm very new to programming and asp.net. Can please anyone tell me how to
dynamically move WbControl from code behind?

e.g.: I have a panel and I want to move it on the web form depending on
some
events.

Let's say that I want to change control's TOP from 20 to 350(in HTML it
looks like style="... TOP:20px, ...".

Thanks in advanced, d
 

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

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,352
Latest member
DianeKulik

Latest Threads

Top