How to call ASP.NET's __doPostBack

Topics: General, Language Specification
Jul 24, 2014 at 2:20 PM
How can you invoke ASP.NET's own __doPostBack method using TypeScript?

It throws a standard "Could not find symbol" error when you try to access the method. I searched around with google but couldn't find a .d typedefinition file for ASP.NET's JS classes/methods.
Jul 24, 2014 at 7:08 PM
.d.ts files only provide type information, not implementations. If the error you're seeing is a runtime one then it sounds like you have not loaded the .js files that provide the implementation for __doPostBack. If you mean you have a variable of a non-any type that is giving you a static error in VS then you would need to provide some type information (either in a referenced .d.ts or your own ambient declarations) that will allow the compiler to verify whether the type you're using actually has a __doPostBack member.
Jul 25, 2014 at 7:05 AM
Edited Jul 25, 2014 at 7:06 AM
I'm not asking for implementation, but type information... and I most certainly cannot load or reference a .js file which contains the definition of __doPostBack. ASP.NET does it itself.

__doPostBack is ASP.NET's very own JavaScript function, it's included in every single WPF website out there. This is the function that ASP.NET itself uses to post back to the server with it's <asp:anything> controls.
There are a lot of cases when developers call this method from JavaScript to initiate a postback in the name of a webcontrol on the page (e.g.: a hidden button). See StackOverflow for reference.

__doPostBack is very commonly used and I find it very strange that TypeScript has no idea what it is. I like TypeScript overall, but I just cannot understand how it doesn't have the type information of ASP.NET's very own javascript functions.
Jul 25, 2014 at 9:00 AM
Looks like this is all I needed:

declare function __doPostBack(eventTarget: string, eventArguments: any);
Jul 25, 2014 at 8:47 PM
It is not feasible for TypeScript to include by default every single piece of type information from common frameworks in its core lib.d.ts. Certainly JQuery, Underscore, etc are also extremely common libraries but we still leave it up to the user to include the necessary type information (generally in the form of a .d.ts from DefinitelyTyped or elsewhere) for the library they want. Did you try the ASP.NET MVC templates with TypeScript configured?