I have jsf component commandButton and I want that at every clock on this button to call bean method "initialize()", but with this code it was called only once at page loading
code is here
http://pastebin.com/MjW1TJxF
From the docs:
onclick - Javascript code executed when a pointer button is clicked over this element.
If you want something to happen on server side, use the actionListener attribute.
(And next time, you can put your code into the question)
Related
I add this in my Render method (custom webcontrol):
Me.Attributes.Add("onkeypress", "chang(event,this);")
If affects some textboxes if they have some properties. But there are times that i don't want this property to be set, so no javascript will be executed. I've tried to remove it in code-behind on page_load and i was going to try to remove it on prerender method but it happens before my controls Render method.
How can i remove this property?
Take a look at the ASP Events Lifecycle. As you can see, the render event is at the bottom of the execution list. Since no events are fired after render, and render is where you are adding this functionality, then render is also where you must remove this functionality.
You could try to move the function that adds it into a higher event (load for example) and then remove it on render. Either that, or when you are applying it, perform any checks to see if the objects requires it or not.
I have a situation where I am loading an iframe inside of a backbone view. The view has an events hash that handles click events.
events: {
'mousedown': 'toggleActive'
}
This works fine for the DOM that the view is part of. Problem is when I click inside the iframe DOM, the click event doesn't bubble up to the view (as expected). So I wrote some code that transfers the click from the iframe DOM to the parent DOM. I have the following inside the iframe body.
$("body").bind("click", function(event){
window.parent.document.$("#"+tgId).trigger(event.type);
});
This works fine for regular jquery event handlers, but for some reason it doesn't trigger the view's event handlers (from the events hash).
Does anyone have any ideas?
Have you tried adding a debugger statement inside your click handler, and then checking what window.parent.document.$("#"+tgId) actually is? It's hard to say for sure, but my guess is that that code is not selecting the element you expect. jQuery will then happily let you call trigger on an empty set, so you would't get any errors if that was the case.
I have the following scenario:
UserControlA contains a <asp:Button id="bSomeid" onClick="AddItem" /> with some code to an item to a shopping basket in AddItem.
UserControlB contains some LinkButton's that dynamically add a selection of UserControlA to the page in the OnClick event.
This is all done in an UpdatePanel. It is a little more complicated but I have pruned the information to what I believe is causing the problem, I will add more information if necessary.
The problem I have is that it takes 2 clicks for the AddItem event to trigger after I have added the items to the page after clicking the LinkButton.
I understand why this is happening - it is to late in the page cycle to register events for the next post back in the onclick - but can anyone think of a way around this? Can I force an event to be triggered on the next postback? I have tried to think of a way to run my code in page_load but I requuire access to the sender in the onClick.
Using .NET 4.0.
EDIT
I managed to find a way to get the link button sending the request in the Page_Load (using Request.Form["__EVENTTARGET"];) so I moved my code to the Page_load event. It still requires 2 clicks so I am assuming it isn't something to do with the onClick being registered to late.
Are there any other general things to check that could cause a button to require 2 clicks to post an event properly?
If your suspicion about being late in page life cycle is true then you can try using ScriptManager.RegisterAsyncPostBackControl method to register dynamically added controls in the link button click - considering that your button is within user control, you need to add public method into UserControlA that would actually register the button bSomeid1 and link button click from UserControlB would actually call the A control's method.
EDIT :
Another cause for button click not happening can be that button being dynamic control is not added in the page hierarchy when post-back happens (or it gets added very late in the page life cycle when the post back data is already processed). A really full-proof solution should add dynamic controls back to the page hierarchy in page_load it-self (and strictly maintaining same controls ids within hierarchy). If that's not possible then you can sniff the request (Request.Form) to detect the post-back.
In your case, you should ascertain if the button is indeed causing the post-back on each click. If yes, what is the POST data (Request.Form) for the first request - what is the __EVENTTARGET value on the first click (and post-back)? That should start your trouble-shooting.
On the other hand, a simple work-around could be to use html anchor element (you can still use link button) and have a javascript handler in the click event that would set some hidden variable and then submit the form (you can simulate the click on hidden button to trigger ASP.NET client side submit pipeline) . Now the hidden variable value can be used on the post-back to determine which link button has been clicked.
"Are there any other general things to check that could cause a button to require 2 clicks to post an event properly?"
Does it require two clicks on the control, or does it take accept a single click elsewhere on the screen, and then fire first time with a single click on the control?
I have my own (similar) issue with the Updatepanel where the first (expected) trigger does not fire and it seems that a single click elsewhere, and then the subsequent triggers fires first time (which totals 2 clicks)
[edit] Since you are working on this ATM, it may help me as well. Do you have a textbox with a trigger event on it? I do, and if I leave this blank (so that it does not fire) then there is no need for a second click.
I have a web page that initially loads a drop down list. When an item is selected from the list, a web form is dynamically created during an update panel async postback.
I added watermark extenders to some of the textboxes, but the watermark does not display when the page is first updated. If I focus in and then out of one of the textboxes, the watermark then appears and seems to work fine. From examining the source, I saw that the client side creation of the watermark was being attached to the init event of Sys.Application on the client.
Here's where I'm getting confused.
1. I added a handler to the client side page Sys.Application.initialize event to see if it was called during the life cycle of an async postback. It didn't appear to fire the event.
2. I tried to raise the initialize event by adding a handler to the PageRequestManager End Request method, but the flags that check if the page was already initialized were set, so none of the individual handlers were fired.
3. After 1 & 2, I thought maybe the watermark extender was somehow being lazy loaded when I applied focus to it. So I put the $create statement that is supposed to be executed in the initialize event in the End Request event of the PageRequestManager. The client script threw an error because the watermark extender was apparantly already created.
I'm not sure what the resolution here is, outside of writing my own watermark code. Is this a limitation (will the extender only function correctly if created in the initial request for the page)? And what about the init event? I can't see it firing, but if the extender was already created, it must have???
Any help would be appreciated. Thanks.
The watermark extension gives headaches to others too. I'd suggest taking a look at a jquery watermark plugin http://jquery-watermark.googlecode.com/
If you have an update panel, that displays a number in its Load method, and a button as a trigger, and you make the button have an onclick method that increments the number, the update panel will not update when you click it.
This is because the update panels Load method runs before the OnClick method, so it draws the number on the screen before it increments it.
At the moment I get around this by using the scriptmanager to tell me which button or whatever caused the update panel to trigger, and then I use that to run the increment method before it renders, which works.
It sucks though because it renders onclick methods for buttons obselete if you want immediate feedback from them, and fills your load method with IF statements.
Am I missing something or is this the intended way update panels work?
That's just the order of the events in the page cycle, and that is the same regardless if you are using update panels or not.
You can use the Page_PreRender event instead to put the number in the page. It occurs after
the click event but before the page is rendered as HTML.