P
pamelafluente
I am trying to pass a javascript variable to ASP.
It almost works, except for the postback part. Infact if one clicks on
the div and on the button it can be seen that the variable passes
through. Can anyone help to do the postback?
Here is my complete code:
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Test Page</title>
<script type="text/javascript" language="JavaScript">
function Hi(MyControlID)
{
var obj = document.getElementById("Hidden1");
obj.value = MyControlID;
__doPostBack(MyControlID,'');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<br />
<br />
<div id="MyDiv" style="width: 100px; height: 100px;
background-color:green" onclick = "Hi('MyDiv')" runat="server" >
</div>
<asp:Button ID="Button1" runat="server" Text="Button" />
<%--Hidden field to store the ID of control clicked--%>
<input id="Hidden1" type="hidden" language="javascript"
runat="server" /><br />
</form>
</body>
</html>
Code behind is:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.Write(Me.Hidden1.Value)
End Sub
End Class
It almost works, except for the postback part. Infact if one clicks on
the div and on the button it can be seen that the variable passes
through. Can anyone help to do the postback?
Here is my complete code:
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Test Page</title>
<script type="text/javascript" language="JavaScript">
function Hi(MyControlID)
{
var obj = document.getElementById("Hidden1");
obj.value = MyControlID;
__doPostBack(MyControlID,'');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<br />
<br />
<div id="MyDiv" style="width: 100px; height: 100px;
background-color:green" onclick = "Hi('MyDiv')" runat="server" >
</div>
<asp:Button ID="Button1" runat="server" Text="Button" />
<%--Hidden field to store the ID of control clicked--%>
<input id="Hidden1" type="hidden" language="javascript"
runat="server" /><br />
</form>
</body>
</html>
Code behind is:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.Write(Me.Hidden1.Value)
End Sub
End Class