I want to run a JavaScript function to initialize some controls.
My problem is that the controls are on a Telerik control's form template that is displayed using AJAX.
Is there a way to specify the JavaScript function executes whenever this template is displayed?
It appears the answer is no. While there are some convoluted ways to trigger JavaScript on an AJAX postback, trying them stopped the Telerik controls from working. I guess they rely on that technique already. Anyway, I've moved on to approach the problem from a different angle.
Related
I have a WinForms app that uses a .NET webbrowser control. What I need to do, is wire up an event on the WinForms side to fire when a value is set (via javascript) in the loaded HTML page. I had success doing this with an onclick event of a button, but I can't seem to get it to work with a custom event. I don't know if this is a limitation in what the browser control can attach to event wise.
So essentially, I need that when a JS function is called in the HTML page and sets a value of a hidden input element (or it could be a regular input that I style to be hidden), I need to know that in WinForms. If it helps, I am using browser flags in this application to emulate IE11 instead of the default IE9 engine. The HTML page loaded is also mine so I can modify it any way needed to make this work properly. I would just use the onclick events of the buttons, but this is a gmaps integration where there can be upwards of 2000 buttons generated (one per marker placed) so it seems like a huge waste of resources to wire up 2000 onclick events when any of those button clicks only modify 4 input fields with the data I care about.
This project happens to be in VB.NET, but C# solutions would be fine as well. They can be transcoded or if the solution uses C# specific features, we can move this to a separate DLL and reference it.
After spending a lot of time on this today, I found a solution. It isn't a direct solution to the problem I posted, but it got me to where I needed to be. I am still interested in an answer to the original problem if anyone has one, but for now, what I found I could do was to create a class in .NET that I could assign to the ScriptingObject of the browser control and then call window.external.myFunctionName, where myFunctionName is a function within the .NET class. This works great for my specific problem, but would not work if I didn't also control the HTML page I was consuming with the browser. That is why I am still interested in alternate solutions if anyone has one. Thanks.
I've searched the net for several weeks but because I just don't know enough javascript to work out how I can turn a CSS3 modal popup into JavaScript that can be loaded from code behind after a button_Click event.
The CSS3 is from https://www.script-tutorials.com/css3-modal-popups/ and I like the look, it resides in /styles/style1.css of the site. The button_click event is in a repeater and after the data is returned I'd like the CSS3 popup to display. I'm not sure how to call a JavaScript function from the code behind. How do I do it?
Not sure about the css into JavaScript but you can do the following. Attach a function to render this modal on the postback using the webforms JavaScript events.
Edit: check out this post
Execute javascript after a partial postback of an updatepanel?
I didn't check out you link but just make sure to serve the assets you need for the modal.
Edit/read it: this is a static demo. You may need to inject some extra Dom elements before or after(using Js) the post back. Once the Dom elements and css are there your modal should be good. Also if you can add the Dom elements for the modal when the repeater is running you don't need any JavaScript.
I am now trying to use gridview to create a web application for users to delete some rows from database. However, whenever I refresh the whole page, strange things happen as selectedIndexChanged was called. Is there any way that I can avoid this method being called whenever I refresh the table or is can I use javascript to detect this event? If not, can I generate a yes no dialog for that event like javascript? I am quite new to asp.net and my questions may be quite stupid. Please help!
I think you need to decide if you want to use JS or ASP to handle events on the page.
If you want to use JS, then disable server processing in your ASP tags and handle all the interactions with JS in your page and only process at the server on page submit. ASP can generate the grid for you on page load, but then let JS handle the client side interactions.
If you want to use ASP, then set your grid to process on the server (runat="server") and forget about JS.
Well seems I found out the solution. Actually C# also provides yes no dialog. Seems I could use it to manually stop that event but it seems that I cannot avoid selectedIndexChanged being called when refreshing the page. Thank you every one for your help.
I am working on a custom control that is being used on a webpage that contains many updatepanels. In my custom control, there is extensive use of jquery and many plugins are used as well. Now, on every updatepanel's postback, THE CONTROL GETS RENDERED AGAIN AND AGAIN, it loads the javascript resources again too, but doesnt call the javascript functions again. This is causing problem that many elements in my control which has to be turned in to one thing or another by jquery plugin are not working(javascript functions not calling in simple).
Now I have tried many solutions, including the ones mentioned in this question
How to have a javascript callback executed after an update panel postback?
but in vain. Previously, when my page contained only one updatepanel,
pageLoad(sender, Args);
functon was working fine, now in the case of multiple updatepanels that is not working, neither
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(pageLoaded);
function pageLoaded() { }
If you don't want your control to refresh on every UpdatePanel's postback - set UpdateMode for the UpdatePanel that hosts your control to Conditional this way it will be refreshed only when its own trigger or child control fire (Ref: http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.updatemode(v=vs.90).aspx).
That said, you don't have to manually add pageLoaded event handler on client side. Use intristic pageLoad function which fires on every page load be it via UpdatePanel or otherwise (Ref: http://msdn.microsoft.com/en-us/library/bb386417(v=vs.90).aspx)
One other way to fire a JS function is from server-side code. Every time your control loads or performs some server-side init - use ClientScript.RegisterStartupscript call to make sure JS function will be called on the client afterward, for example
ClientScript.RegisterStartupscript(this.GetType(),"myFunc", "myFunction();", true);
Ref: http://msdn.microsoft.com/en-us/library/z9h4dk8y(v=vs.90).aspx
I have an ASP.NET application with a button that executes VB.NET on the server when clicked.
Specs have changed, I've added a menu of sorts which is to replace the VB button. With some help from S.O., I've managed to manipulate some javascript which does a postback and executes the button's code. I figured I could just make the button invisible and still be able to call it's on_click event from js. How wrong I was!
So now, somehow I'm supposed to call a VB sub from either javascript or (boss says) ajax. I have no idea how to do this.
Could anyone give me a good direction as to how I can call a VB.NET subroutine from ajax on the client? Or javascript?
Thanks in advance,
Jason
It's not obvious that you could just switch to Ajax from a postback scenario, whatever your boss tells you. :-) Lots of stuff might happen in a postback that you don't do in an Ajax call; setting other values serverside, changing visibility and such. It's hard to tell without seeing the actual code, though.
The easiest way for you now would be to be able to "click" that button again. The problem is how you set the invisibility, some types of invisibility makes the button disappear from the form, leaving it impossible to press it even programmatically.
Again, without seeing the code it's hard to tell which way you should go, but to hide it with css will make it possible to "click" it the way you have done. Hiding it with "button.Visible = false" server side won't.