Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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!
Posted

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?
 
Share this answer
 
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
 
Share this answer
 
v2
wrote:
when I did registered it using the "onclick" attribute, it never got to the "RaisePostBackEvent"


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:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900