简体   繁体   English

如何在asp.net中的page_load之外访问__doPostBack Eventtarget值?

[英]How to access __doPostBack Eventtarget value outside page_load in asp.net?

I am using __doPostBack to send data from JavaScript to code behind page in ASP.NET application. 我正在使用__doPostBack从JavaScript发送数据到ASP.NET应用程序中页面后面的代码。

The JavaScript is as follows, JavaScript如下,

$('.window_month td').on('click', function () {
    var idName = this.id;
    var selectedid = idName.substring(1);
    $('#hidden').val(selectedid);
    __doPostBack(idName, '');
});

I am using the variable like this in .cs page, 我在.cs页面中使用了这样的变量,

string s = Request["__EVENTTARGET"];

I want to use this __EVENTTARGET value outside of page_load and assign it to a global variable in ASP.NET. 我想在page_load之外使用此__EVENTTARGET值,并将其分配给ASP.NET中的全局变量。

How can I do this? 我怎样才能做到这一点?

Used Session and it worked. 使用会话,它的工作。 Thanks all. 谢谢大家

then you will need to have a static property or store it in a Session variable because if your are doing postbacks on the page load the public string variable would be overwritten and set to string.Empty on every page load.. I would personally initialize a HttpContext.Current.Session["Target"] = string.Empty in the Global.asax page in the OnSessionStart() method and then assign it and from there you can access it application wide.. does that make sense..? 那么您将需要具有static property或将其存储在Session variable因为如果您在页面加载中进行回发,则public string variable将被覆盖并设置为string.Empty 。每次我加载页面时,我都会亲自初始化一个HttpContext.Current.Session["Target"] = string.EmptyOnSessionStart()方法的Global.asax页面中,然后对其进行分配,然后您就可以在整个应用程序中访问它了。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM