views:

53

answers:

1

In a simple aspx page I can have a custom JavaScript function postback as described in http://www.xefteri.com/articles/show.cfm?id=18 The simple page uses a linkbutton:

<asp:LinkButton id="CreateFile" runat="server" onclick="CreateFile_Click" />

with code behind that has the VB subroutine:

Sub CreateFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

and a Javascript custom function that does:

 __doPostBack('CreateFile','');

When I move the code to a content page with a corresponding master page the simple example no longer works.

I'm aware that server control IDs are changed in the generated HTML when a master page is involved, and I'm using the correct IDs in the Javascript. As an example, for the LinkButton ID I use '<%=CreateFile.ClientID%>' for the Javascript in the generated HTML. Never the less, I still can't figure out how to get postbacks from the Javascript when master pages are involved. More accurately, with a master page in the mix the code won't even compile but results in:

'CreateFile_Click' is not a member of 'ASP.testmaster_aspx'

If I remove onclick="CreateFile_Click" from the LinkButton markup it compiles but does not work. Similary if onclick is removed from the simpler version without a master page it does not work either, as expected.

Any input on how to get postback from a custom Javascript function when using master pages would be much appreciated.

A: 

are you hard coding the call to __doPostBack?

try using Page.GetPostBackEventReference

to obtain a valid handle in your javascript.

once you write out a valid post back event reference, you could wrap it inside a local function, which you can than call from master page.

if (window.myPostBackfunction) // check if it exists
  myPostBackFunction();
Sonic Soul
I didn't want to hard code the call to __doPostBack, and your pointer to GetPostBackEventReference was right on. Thanks!
harrije