Hello Support.
I am using an aspNetPanel with the PageSource attribute set to an HTML document. In the HTML document I am using javascript to call a method in my Form class but the method doesn’t get called, it just stops the javascript executing (I can put an alert before and after the call and I don’t see the message from the alert call that is after the App call).
The javascript call looks like:
App.MyClassName.ShowMessage();
The C# ShowMessage() method has the [WebMethod] attribute. When I put the App.MyClassName.ShowMessage(); line into the aspNetPanel’s InitScript property the method gets called.
Can I make a method in my C# class be called from the PageSource code ?
Thank you
Andrew
Hi Andrew,
To achieve your goal, you’ll have to move the script from the “PageSource” HTML file to the application’s Default.html file, or add it to the HtmlPanel’s InitScript property.
You can think of the HtmlPanel as a sandbox, even if you call the “this.App.Window1.HelloWorldFromHTMLSource()” method from firing the click event you’ll get “this.App” is not defined on the Console.
It’s a security measure, so you’ll have to define all the scripts from the beginning in Default.html.
You can check out these forum posts for more details:
https://wisej.com/support/question/firedataevent-from-innerhtml-of-htmlpanel
https://wisej.com/support/question/get-filled-html
https://wisej.com/support/question/topaz-wisej-integration
Or better yet, you can actually integrate your javascript library as a widget!
You can check out the documentation for more info through this link: Wisej.NET | Widget
I have also attached a modified version of your sample for you to try!
HTH,
Alaa
Hello Frank. Thank you for helping with this question. I have attached a short example project to show the problem I am having. When you run the project if you click on the ‘Call javascript in Initscript’ button it will call a javascript function which is defined in the InitScript attribute of the aspNetPanel and that javascript function will show an alert and then call a method in the Form class that will show a MessageBox. This all works.
But the next button ‘This is PageSource javascript – Call a C# method’ doesn’t work as I expect. It calls a javascript function which is defined in the page linked to the PageSource attribute of the aspNetPanel. The javascript function shows an alert (which we see) and then calls a method in the Form class – but the call doesn’t happen, the javascript fails silently. This is my problem – I would like to be able to call a C# method from javascript in the PageSource file. (I am using the PageSource file because in my real project I have to include a 3rd party javascript library which provides some functionality that returns a value and I need to get that value back to my C# code, the 3rd party javascript library works with a PageSource file so I thought that was the best way to go, if there is another way of doing this (not with an aspNetPanel, not in PageSource etc.) then I am open to any ideas).
Also in the example project there is an HTMLPanel which has some javascript in the html file that is in the HtmlSource attribute. I can’t get the button in that panel to call the javascript function – maybe this is a different problem ? If you click the ‘Call Method’ button it doesn’t seem to call the MakeCall javascript function (maybe this a problem with my limited knowledge of html/javascript).
Thanks for your help
Andrew
Hi Andrew,
is the function declared as public static? Please also note the last paragraph in our docs about RemoteMethods
https://docs.wisej.com/docs/concepts/javascript-object-model#remote-methods
If it still fails after using the mechanism described there, please wrap up a small repro case that we can use to inspect that issue.
Thanks in advance.
Best regards
Frank
Please login first to submit.