NoBullMan
NoBullMan

Reputation: 2184

doPostback Error

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.

Upvotes: 0

Views: 1514

Answers (1)

Sen Jacob
Sen Jacob

Reputation: 3442

You can use the __EVENTARGUMENT as explained in this article.

Doing or Raising Postback using __doPostBack() function from Javascript in Asp.Net

Try passing concatenated values as a single __EVENTARGUMENT and split it at server to get actual arguments

Upvotes: 3

Related Questions