来自自定义服务器控制问题的回发 [英] Postback from custom server control problems

查看:66
本文介绍了来自自定义服务器控制问题的回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我正在研究基于Ajax的上下文菜单.

menuItem实际上是表格单元控件,每个控件都具有"onClientClick"和"OnClick".

我的问题是-单击menuItem时如何引发回发?

我知道我应该实现"IPostBackEventHandler"
并使用以下命令注册__dopostback:
"Page.ClientScript.GetPostBackEventReference(this,String.Empty);"

但是:

1.如何在不使用"addAttribute(" onclick"...)的情况下注册" __dopostback方法?
2.当我使用"onclick"属性注册它时,它从未到达"RaisePostBackEvent"(从IPostBackEventHandler接口)
我想念什么?


Hi!

I''m working on an Ajax based context menu.

the menuItems are actually table-cell controls, and each has both "onClientClick" and "OnClick".

My question is - how do I raise a postback when a menuItem is clicked?

I know I should Implement "IPostBackEventHandler"
and also register the __dopostback using this:
"Page.ClientScript.GetPostBackEventReference(this, String.Empty);"

but:

1. how can I register the "__dopostback" method without using "addAttribute("onclick"...)? asp.net controls seem to do it otherwise.

2. when I did registered it using the "onclick" attribute, it never got to the "RaisePostBackEvent" (from the IPostBackEventHandler interface)
what am I missing?


Thanks in advanced!

推荐答案

您正在使用表还是数据网格类型的控件?我要了解的是每个单独创建的表单元,还是由某种模板创建的表单元?
Are you using a table or a datagrid-type control? What I am getting at is are the table-cells each created individually or are the being created by some sort of template?


contextMenu的menuItems是自定义类(MenuItem),其中继承TableCell,并将每个Cell插入到上下文菜单正文中的表中.
我没有使用数据网格.

您将以与创建表几乎相同的方式创建上下文菜单.

因此,基本上,"MenuItem"和"TableCell"之间的主要区别在于,可以单击menuItem并激活服务器端方法...这就是我遇到的问题
The menuItems of the contextMenu are of a custom class (MenuItem) which inherits TableCell, and each is inserted into a table which is the body of the context-menu.
I''m not using a data-grid.

you would create a context menu pretty much the same way you''d create a table.

so basically the main difference between "MenuItem" and "TableCell" is that the menuItem can be clicked and activate a server-side method... that''s what I''m having trouble with


写道:​​

当我使用"onclick"属性进行注册时,它从未到达"RaisePostBackEvent"

when I did registered it using the "onclick" attribute, it never got to the "RaisePostBackEvent"



我认为您在代码中一定做错了.否则,将在页面回发时自动调用RaisePostBackEvent处理程序.

我认为您可能会研究 http://www.myviewstate.net/blog/post/2009/05/14/Implementing-IPostBackEventHandler-in-an-ASPNET-Control.aspx [



I think there must be something wrong you did in your code. Otherwise RaisePostBackEvent handler will automatically called when page is posted back.

I think you might look into http://www.myviewstate.net/blog/post/2009/05/14/Implementing-IPostBackEventHandler-in-an-ASPNET-Control.aspx[^] for complete example on this issue.

ASP.NET actually puts some code in onsubmit event of form. Thus based on its id, it raises the callback.
It is very similar to what you are doing. so dont worry how asp.net does. You are actually overriding the normal process of asp.net using IPostBackEventHandler.

Cheers.
:cool:


这篇关于来自自定义服务器控制问题的回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆