I have an asp.net web form with a button, label, scriptmanager and updatepanel controls. When I click the button, the label changes using ajax. How can I detect the change in the label using javascript?
You need to use add_endRequest,
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
function endRequestHandler(sender, args)
{
alert("ended");
}
You are using ajax to change or update something on some event. If it changes naturally your output will be changed. If it is some kind of change that doesn't change output but change any attribute then
1. Install firebug addon2.use it when firing your ajax function.
3. On console mode you will see any change of error which you are expecting from the code
You can use update progress for this purpose.
Here is a good example for update progresshttp://www.devmanuals.com/tutorials/ms/aspdotnet/updateprogress.html
Related
I'm using the CKEDITOR 4 onchange event like mentioned here SO Link
. I have 10 text areas which act as a CKeditor. I'm planning to use on change event to pass the data to ajax and save it to database for faster saving but the problem is CKeditor onchange fires every character's change. If that happened,then there will be lot of requests to DB. how to make it like normal onchange means if particular textarea's data completely edited then the ajax request will make request to DB. help me to achieve this. code that has been used for onchange
CKEDITOR.instances.editor1.on('change', function() {
console.log("TEST");
});
Thanks
I need to know when a user tweets my blog's content because I want to register that activity on the database, is there any way to do that? Using a simple button like this one?
Tweet<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
Or how can I do it? Maybe using API's callback?
At first I thinked about adding an event listener to the anchor, but that wouldn't work, because Twitter's API converts it to an iframe.
Reading a bit the Twitter's JavaScript Widget API Docs I came up with this:
twttr.ready(
function(twttr) {
twttr.events.bind('click', function(event) {
//Here you can place your code for an AJAX call
console.log('click on share button')
});
});
Codepen: http://codepen.io/anon/pen/grEBvr
Note: it triggers on click, so not when the user actually shared, didn't find an event for shared.
Note 2: had to remove the async attribute in the <script>, was giving issues like "twttr is undefined".
I'm after what seems to me to be a straightforward pattern for handling page refreshes when I've got a drop-down that reacts to the onchange event.
I've used the following in the vb code behind (in the Load handler):
MyDropDown.Attributes.Add("onchange", "ProcessDDChange(this.value);")
Function ProcessDDChange() is in-page JavaScript that grays out some other form inputs for certain values of the drop down.
This works fine, but after a postback, onchange is apparently not fired when the previous state is restored, so disabled boxes are enabled again.
I've investigated load events (page and drop-down), but both fire too early to be of use and I can't see any later options.
Is there a standard way of doing this? I need a hook for running a js function post DOM setup, post asp state restore.
Info
I'm using .net 3.5 and I'm looking for a cross browser solution. This is not my project, so I can't add jQuery (much as I'd like to) or other libs.
You could wrap the dropdown in an update panel and set the trigger for the change event like epascarello suggests. Have you tried adding it to the markup like
<asp:DropDownList runat="server" ID="MyDropDown" onchange="ProcessDDChange(this.value);"></asp:DropDownList>
EDIT:
So you are loosing the onchange listener when you postback, the above example should preserve it. But if not you could also try this in the codebehind event that you would like to have call the ProcessDDChange: for vb.net
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "err", "ProcessDDChange(this.value);", true);
FINAL EDIT:
Thanks for sticking it out with me Bob, while I was attempting to understand the question:
The document.ready event is raised after the PageLoad event is complete and the DOM is constructed. This would be the proper place to call your ProcessDDChange().
document.addEventListener("DOMContentLoaded", function(event) {
ProcessDDChange(ddlId.selectedValue);
});
onchange does not fire when the page loads. You would need to trigger the function on page load OR you need to have the server set up the page correctly from the start.
Can anyone please help me in finding the solution?
I have a h:commandButton which calls a action and fires actionListener after that.
But due to change in requirements I have removed the action attribute and added onclick Javacript function which calls a customized dialog. So now, the actionListener is not being fired where i have set some values using the button value.
Please tell me if there is any alternative in solving this.
U can use the below code inside the jquery
document.form[0].sumbit();
this line will submit the form to back end bean
I have an ASP.NET button. When the button is clicked, I'd like a modal popup to display after the server-side code for the button runs. I don't want to use the ASP.NET Ajax control toolkit modal popup extender.
With ASP.NET Ajax, I can hook into the end request event. Is there a way to do this without ASP.NET Ajax. just jQuery? I basically want to run some javascript after the server side click code runs, after the postback.
You can use ScriptManager.RegisterStartupScript() for this, something like this:
ScriptManager.RegisterStartupScript(MyUpdatePanel, GetType(), "post-load-script",
"$(function() { $('#dialog').dialog(); });", true);
Then the request from the UpdatePanel comes back it would be running this:
$(function() {
$('#dialog').dialog();
});
You could of course put anything you wanted for script there, but if you simply used a Label or whatever in the #dialog <div> that populated as part of the update, this would show it (if you're using the jQuery UI dialog, there are others). The concept is very general, you're just registering some JavaScript to run when the async request comes back, which modal and how you want to do that is very open.
It depends on what method you intend to use to start the postback via jQuery. If you're going to use an async postback (like jQuery.ajax), you can just provide a method to call when the postback is complete. See http://api.jquery.com/jQuery.ajax/.
If you're just going to use the normal postback, you can use the Page.ClientScript.RegisterClientScriptBlock from your server-side method to register a script that will run after the postback completes.