I am currently working on an ASCX page.
On the ASCX page, I have a DIV that looks like this:
Code:
<div id="divElement0"></div>
On the ASCX code behind page, I set the DIV style properties on Page_Load():
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strScript As New StringBuilder
If Not Page.IsPostBack Then
strScript.Append("document.getElementById('divElement0').innerText = ""xxx"";")
strScript.Append("document.getElementById('divElement0').style.left = ""354px"";")
strScript.Append("document.getElementById('divElement0').style.top = ""194px"";")
End If
Page.ClientScript.RegisterStartupScript(Me.GetType(), "test", strScript.ToString, True)
End Sub
The page loaded successfully, with the DIV appeared as set. I can also change the position of the DIV by dragging it around.
Now, I am having problem when I try to retrieve the DIV style properties value via a button click.
Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Page.ClientScript.RegisterStartupScript(Me.GetType(), "test2", "alert(document.getElementById('divElement0').style.left);", True)
End Sub
I expect it will show the DIV's left position as 354px or whatever it is depending on where I dragged it to. However it just show nothing in the message box.
How can I fixed this? Please help. Thank you.