0

I am trying to execute a javascript function on page load and then do a postback that would call a function in code behind. I am getting time zone data and trying to pass them as arguments to __dopostback. Here is what I have (abbreviated):

in .aspx file

<body onload="GetLocalTime()">
....
function GetLocalTime(){debugger
    var d = new Date();
    var tzOffset = d.getTimezoneOffset();
    var hfOffset = document.getElementById('<%=hfOffset.ClientID%>');
    var hfTZName = document.getElementById('<%=hfTZName.ClientID%>');
    var tzName = getTimezoneName();
    hfOffset.value = tzOffset;
    hfTZName.value = tzName;
    __doPostBack('TZSessionVars', tzOffset, tzName);
}

In code behind's Page_Load(), if IsPostback is true:

string sTarget = Request["__EVENTTARGET"];
if (sTarget.Equals("TZSessionVars"))
{
    string sArg = Request["__EVENTARGUMENT"];
    SetTZSessionVars(sArg);  // this is where I parse the argument and set session vars
}

When I trace the javascript, when it hits __doPostback, it says:Microsoft JScript runtime error: Object expected

The parameters tzOffset and tzName are OK and have valid values.

4

1 回答 1

3

您可以按照本文中的说明使用 __EVENTARGUMENT。

在 Asp.Net 中使用 Javascript 中的 __doPostBack() 函数执行或提高回发

尝试将连接的值作为单个 __EVENTARGUMENT 传递并在服务器上拆分它以获取实际参数

于 2013-02-21T18:10:29.767 回答