ajax not working properly in jsf 1.2 - jsf-1.2

I have implemented AJAX in jsf 1.2 by using ajax4jsf-1.0-6.JAR in my project.
There is a requirement that I have to show a datatable inside a "div" on click of a button on the same page.
I am calling a method on click of a a4j:commandButton which is setting those values which will be rendered in "div" element and in onComplete attribute I am calling a javascript function which displays "div".
But the problem is that values are not being displayed. I checked the console and found that values are being printed by logger.
One more thing if I refresh the page by clicking on any button , after that values are being displayed. so I think there is problem with "UPDATE MODEL VALUES".
I am unable to post the code. But think you will get idea what i am talking about.
help me ,
thanks in advance.....

The is page not render after click on button.
To get out of this problem you include a4j:support component in between the a4j:commandButton component. Mention the event, reRender attributes. Write the form id value in reRender attribute.
<a4j:commandButton>
<a4j:support event="onclick, oncomplete" reRender="yourFormId" oncomplete="yourDivFun();"></a4j:support>
</a4j:commandButton>

Related

How to rebind datagrid in asp.net 1.1 without postback?

I need to have datagrid(3 columns) to which the values will be added using 3 textboxes and a button(Add) on the same page. If click on Add button the value should append to datagrid without page refresh/reload?
Please guide me with your approaches to this problem? I ran out of search.
Have you considered using Ajax on the client-side? I presume that clicking the "Add" button is also supposed to update something on the back-end, which means you must do a round-trip of some kind. Either via a postback, but since you don't want this, then the only other option is Ajax whereby you'll make a separate asynchronous post to the back-end that will not cause a page refresh, and on the client script, inject the correct elements to "update" the grid on-screen. You could get that working as a prototype and then use knockout to simplfy the process.
1) I have used iframe in my default aspx page.
2) Created a new aspx page "datagrid.aspx" and had my datagrid as the only control in that page and set the src attribute of iframe to "datagrid.aspx"
3) Datatable to be rendered in datagrid.aspx is stored in the session variable in page load of default.aspx.
4) In the pageload of datagrid.aspx datatable is retrieved and binded to the datagrid.
5) When an item to be added/updated/removed are sent through querystring parameters from default.aspx using onclick event (JS) of a html button by setting the iframe source attribute.
Hope this answer helps.
If its not clear, Please comment.

Can I have a modal dialog from asp.net gridview edit click?

I am wondering if it is possible to have a modal dialog (like JQuery) by clicking Edit button on a asp.net built in gridview control. If yes, can anymore point me out the brief process of how it could be done. Please see the picture below for clarification.
Thanks.
I see few ways to do that:
Using OnEditCommand property (assuming you are using <asp:EditCommandColumn to draw that edit link):
You can show popup using serverside handler (for instance, popup included into ajaxcontroltoolkit.dll which allows to show popup from serverside easily on page reload)
Another option:
Make your own column with edit link for each item. It can have OnClientClick handler which will open jQuery popup directly on client (but you will need to get row info for current line from server somehow: with your own ajax call or, suppose it will be better, using webservice with webmethod)
Second option could be modified: instead of creating own column, you may add click even handler with that same jquery on default edit link with return false, so it will prevent form submition.
I never did something like this personally and even newer saw implementations of such thing, but I would select some option from those listed above. I do not think that there is some really simply, built in way of doing that.
UPD:
Here is an example of opening popup with own edit button and modalpopupextender from ajax control toolkit (similar like in my first option except that they are using own edit button, which I think could be easily replaced by default one and OnEditCommand even handler) :
http://www.c-sharpcorner.com/UploadFile/krishnasarala/edit-gridview-row-with-model-popup-extender-in-Asp-Net-ajax/

Page does not render after SelectedIndexChanged event of dropdownlist in UpdatePanel

I have one dropdownlist (with static listitems). On SelectedIndexChanged event of this dropdownlist, I have three cases to check:
1) If the value is 'A', I need to bind another dropdownlist.
2) If value is 'B', I need to hide above another dropdownlist and instead show nothing in place of that i.e. ulitmately hide that particular div.
3) If values is 'C', I need to hide above div and in place of that, show a textbox.
Now, to prevent Page postback each time a value in dropdownlist is changed, I am using UpdatePanel control here.
I have tried using single updatepanel for both these dropdownlists, two separate udpatePanels for each of them.
With two separate updatePanels, I could succeed in calling the "SelectedIndexChanged" event of that dropdownlist, but once the event is called, the changes done in that code are not reflecting on the page.
i.e. if I hide a div when selected value is 'B', it still shows me, or in either case if it is 'A' and I bind another dropdown, it does not even render.
And, if I reload that page, the pervious changes get reflected. Can anybody please tell me what could be wrong here?
Also, please note that I want be able to postback the page programmatically, because that is the I am trying to prevent.
Also, I would like to notify here that I am using all these things in a WizrdStep of an asp.net wizard control.
Would be greatful for any help.
Thank you in advance.
The issue was not because of update panel or dropdownlist.
The problem was with the way my page was being rendered.
I have used url rewriting for my application and I was trying render this page using my customized form tag instead of built-in Html form tag.
That is why updatepanel was not working normally.
I have got it working now using normal Html Form tag and meanwhile I am trying to workout to handle this updatepanel tag as well with my customized form tag.
If I get it solved, I will submit the solution.
Thanks.

How Does ASP.NET Knows Which Button Caused a PostBack?

I'm using ASP.NET 4 to create a page with elements that are used in a jQuery UI Sortable plugin.
All of these elements contain a button (implemented as a submit button) with the name SubmitButton. All but one of these buttons are hidden in the page's Load event. But if I drag the element to another position, and then submit the page using that button, ASP.NET gets confused.
ASP.NET thinks I've clicked a different button, one that wasn't even visible on the page, but is associated with content at the position where the clicked button was before the move. (If I don't move the element, it works fine.)
I can't seem to determine how this is happening. As I understand it, ASP.NET knows which submit button caused a postback because the button's name and value is included in the postback data. (__EVENTTARGET plays no role here and is empty.) So how can it think a different button submitted the page?
How could ASP.NET get confused about which button submitted the page?
(Sorry, it's not possible to put this page on a public website.)
I worked through this issue and here's what I found.
First of all, buttons by default are rendered as <input> tags with type = submit. The postback mechanism in this case has nothing to do with ASP.NET. The postback data includes, among other things, the name of the submit button that caused the postback along with the button's text (in the form name=text).
But ASP.NET button names, by default, include the names of all parent controls. When those controls are unnamed, they are given an ID like ctl00, ctl01, ctl02, etc. The result is that all my buttons are guaranteed to have a unique name.
The problem is when these buttons and parent controls are all created dynamically. On the postback, these controls are reconstructed in the load event but in the new order. Because the order affects the name (ctl01 vs ctl02), this means my submit button has a different name than it did when the page was originally rendered.
The result is that ASP.NET sees the wrong name associated with the submit button used to trigger the postback.

LinkButton alternative? (Need it to function like a normal link)

LinkButtons are giving me headaches. I thought, foolishly, that they allowed you to create programmatic links. Obviously this is not the case (by design), as they have behave nothing like normal links - you can't see your address when you hover over them, you can't open them in a new tab, etc.
Is there an alternative in .NET that actually lets you programmatically create a true HTML link? The ability to open multiple items in tabs is sort of a requirement. I've looked into styling a Button to look like a link, but it still behaves like a button, so this won't work either. Any ideas?
EDIT: Sorry, forgot: can't use HyperLink, as I need the ability to send CommandArguments, set OnClick events, etc. It needs to function as a button still.
The HyperLink control.
Set the href using the NavigateUrl property, and tagets (for new windows/tabs) can be set using the Target property
Edit to respond to question edit
I'm not really sure what you're after - your question is asking for a control that "functions like a normal link", so that clicking on it can open in a new window/tab, but your edit says you want to be submitting CommandArguments and using the OnClick event - so not a normal link.
The problem you've got here is that the PostBack processing of command arguments and OnClick events happens at the server, but the "open in a new window" happens on the client (using the "target" attribute of the anchor tag, or possibly with JavaScript) - these two don't really mix all that well.
A couple of options spring to mind:
Use a LinkButton, and if you handle a PostBack, output some JavaScript to open the new page in a new window.
Use a HyperLink control with a target and set the "CommandArguments" as a querystring element to the link - you can then process that on the catching page that opens in the new tab.
You can also cause JavaScript to fire onClick using the Attributes collection:
// Create a hyperlink
HyperLink link = new HyperLink();
link.NavigateUrl = "/somepage.aspx?arg=First";
link.Target = "_blank"; // Open in a new window
// Add a client side onClick event calling someMethod function with a reference
// to the link, and making sure the link processing stops.
link.Attributes.Add("onClick", "someMethod(this);return false");
You mean HyperLink?
Of course you could always use the a tag in HTML.
EDIT: When you hover over a link, the browser displays the target. When you hover over a LinkButton, the browser displays the javascript call that will execute the function server side. I'd say the best you can do is display the target page in the ToolTip, since I think it would be pretty tough to display it in the browser.
If you use a LinkButton you will be able to set the command arguments and the onclick method in your code behind. By doing so, you will no longer be able to open the link in a new window as you have found out.
One of the reasons that you cannot open a LinkButton in a new window is because it is doing a postback to the same page.
I think you either have to use a HyperLink control and pass the command argument as a query string parameter or use a LinkButton control and loose the open in a new tab functionality.
If you pass the argument as a query string parameter, then you can check for that param in page load and still call your onclick function which you were going to use for your LinkButton.
Hope this is clear and it helps you.

Resources