如何获得标识更新面板,最初的在JavaScript的请求 [英] How to get Id update panel that initial a request in javascript
问题描述
我想知道的标识更新面板,最初的要求在JavaScript中。我写这个剧本,但它返回未定义
。
VAR PRM = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
功能InitializeRequest(发件人,参数){
警报(sender.ID);
}
功能EndRequest(发件人,参数){
}
发件人
不为空,它返回 [对象]
但我怎样才能获得 ID
?
修改1)
我认为当的UpdatePanel
在里面母版
不work.this是我的code:
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){
变种PRM = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
功能InitializeRequest(发件人,参数){
变种UpdPanelsIds = args.get_updatePanelsToUpdate();
警报(UpdPanelsIds [0]);
}
功能EndRequest(发件人,参数){
如果($('。AlarmLogo')。VAL()==3){
警报('尼玛');
}
}
});
< / SCRIPT>
和
<形式=服务器>
< ASP:ScriptManager的ID =ScriptManager1=服务器>
< / ASP:ScriptManager的>
< ASP:定时器ID =计时器间隔=4000=服务器OnTick =timer_Tick/>
< ASP:UpdatePanel的ID =UpdatePanel1=服务器的UpdateMode =条件>
<的ContentTemplate>
< ASP:面板ID =pnlAlarm=服务器的CssClass =pnlAlarm的ClientIDMode =静态>
&所述; A HREF =#>
< DIV ID =报警>
< ASP:文本框ID =lblContent=服务器文本=HHHEEELLLOOO的CssClass =AlarmLogo的ClientIDMode =静态>< / ASP:文本框>
< / DIV>
&所述; / a取代;
< / ASP:面板>
< /的ContentTemplate>
<触发器>
< ASP:AsyncPostBackTrigger控件ID =计时器/>
< /触发器>
< / ASP:UpdatePanel的>
< DIV CLASS =主>
< ASP:的ContentPlaceHolder ID =日程地址搜索Maincontent=服务器/>
< / DIV>
< /形式GT;
和落后code:
保护无效的Page_Load(对象发件人,EventArgs的)
{
如果(!的IsPostBack)
{
会话[尼玛] = 1;
}
}
保护无效timer_Tick(对象发件人,EventArgs的)
{
}
您可以使用 get_updatePanelsToUpdate
返回数组与将要去的UpdatePanel的ID更新。
<脚本>
在window.onload =功能(){
变种PRM = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
};
功能InitializeRequest(发件人,参数)
{
//获取更新面板ID阵列
变种UpdPanelsIds = args.get_updatePanelsToUpdate();
//获取帖子ID
。args.get_postBackElement()ID;
}
功能EndRequest(发件人,参数){
}
< / SCRIPT>
http://msdn.microsoft.com/en-us/library/ ee224805.aspx
I want to know Id update panel that initial a request in JavaScript .I write this script but it return undefined
.
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
function InitializeRequest(sender, args) {
alert(sender.ID);
}
function EndRequest(sender, args) {
}
sender
is not null and it return [object]
but How I can get ID
?
Edit 1)
I think when UpdatePanel
be inside MasterPage
it does not work.this is my code:
<script type="text/javascript">
$(document).ready(function () {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
function InitializeRequest(sender, args) {
var UpdPanelsIds = args.get_updatePanelsToUpdate();
alert(UpdPanelsIds[0]);
}
function EndRequest(sender, args) {
if ($('.AlarmLogo').val() == "3") {
alert('nima');
}
}
});
</script>
and :
<form runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="timer" Interval="4000" runat="server" OnTick="timer_Tick" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlAlarm" runat="server" CssClass="pnlAlarm" ClientIDMode="Static">
<a href="#">
<div id="Alarm">
<asp:TextBox ID="lblContent" runat="server" Text="HHHEEELLLOOO" CssClass="AlarmLogo" ClientIDMode="Static"></asp:TextBox>
</div>
</a>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer" />
</Triggers>
</asp:UpdatePanel>
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
</form>
and code behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["nima"] = 1;
}
}
protected void timer_Tick(object sender, EventArgs e)
{
}
You can use the get_updatePanelsToUpdate
that return an array with the Ids of the UpdatePanels that will be going to updated.
<script>
window.onload = function() {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
};
function InitializeRequest(sender, args)
{
// get the array of update panels id
var UpdPanelsIds = args.get_updatePanelsToUpdate();
// get the Post ID
args.get_postBackElement().id;
}
function EndRequest(sender, args) {
}
</script>
http://msdn.microsoft.com/en-us/library/ee224805.aspx
这篇关于如何获得标识更新面板,最初的在JavaScript的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!