i have created Array of Linkbutton
and when user click on link button it will create an array of Radio Buttons
but it requires Postback all time so page load takes more time...
what is solution of it??
Use asp.net Ajax update panel.
Put link buttons and panel/view (or what ever control you are using ) update panel.
I am not sure if I am following a 100% but if you don't want to do a post back then your going to need to write some javascript(or use a framework like jquery) to generate radio buttons when the user clicks the link button(plus you probably don't want to use a link button then as it will try to always cause a postback or you will need to stop the post back from happening).
Related
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.
This is what I'm trying to do with AJAX:
[DropDownList]
I have a DropDownList (not inside an UpdatePanel), populated by different Products to "Add" to the database.
[UpdatePanel #1]
Below, I have an Conditional UpdatePanel that listens for "SelectedIndexChanged" on the DropDownList, when that event is triggered it adds TextBoxes to a div "productForm" inside the UpdatePanel. It creates the Form according to the Product to add.
[Button]
Below the UpdatePanel I have a button that "should" submit the form above.
[UpdatePanel #2]
I have an update panel that listens for the event on Button "Click" event. I also have a div in the ContentTemplate that should post out data that was submitted from the "Add Product Form" in the first UpdatePanel.
The thing is, when I submit (and the Controls are still visible in the first UpdatePanel. It can't read the data from the TextBoxes becaus they aren't there. Also, if I try to add all this to the same UpdatePanel, the Controls disappear whenever I click the Submit button.
Any ideas how to make something similar work?
Without the code I can suspect that when you dynamically populate first div on dropdown selected index changed event, since its within update panel, viewstate is never made aware of new controls and on submit can't post them back to server.
I've had some bad experiences with update panel and never use it other than very simple scenarios. Try getting familiar with jQuery ajax. I would do what you want to do using jQuery and web methods.
I have a GridView on PageA, I wish to be able to call the DataBind() method of the GridView from PageB?
Basically PageB is a form which will be contained in a pop up control, when the user fills in the fields of the form on PageB and submits it I will close the pop up control, then I want to refresh the GridView on the parent page (PageA), how would I go about doing that?
Write a javascript function on Page A like RefreshGrid, you can write various ways to refresh grid from this javascript function e.g.
1) put your grid inside an update panel and create a trigger button control on that update panel , call this trigger control's click event in javascript , this will partial post back the page and refresh the update panel. There are other ways too..
2) From popup on popup close button, write following line
window.opener.RefreshGrid(); window.close();
Thats it.
If you want to pass any parameter you can pass through as argument to RefreshGrid function.
Still there are many ways , this is the one I use.
I have an aspx page that is wrapped with an UpdatePanel control, users can post comments and delete them later, when the user clicks the delete for the first time it deletes successfully but if he wants to delete another comment, it works only after two clicks on the button.
the delete button is inside a web user control that is added dynamically at run time.
Any ideas?
Thanks.
I had a bit different problem. The control event did not work at all after AJAX post back. Here is the possible solution to your problem - http://sharepointtechie.blogspot.com/2011/04/click-event-stopped-firing-after-ajax.html
Please register that control during page load event of the control..
So if you are calling usercontrol1 dynamically during the runtime..
then on the page load event of usercontrol.ascx you should have
this.id="xyz";
try this... It did some miracle for us...
Hope this works for you too
I have a ListView on a page that displays a list of widgets. When a user clicks on one of the items in the list, I want to display a ModalPopup that contains controls allowing the user to operate on the item they selected.
I could easily accomplish this by placing a Panel and a ModalPopupExtender in the ListView's ItemTemplate, but this mean one set of hidden controls for each and every widget, which would massively bloat the page size. (There are going to be some rather heavyweight controls in there.) Instead I want to reuse a single ModalPopup for each of the widgets in the list.
I've done some searching but I haven't found anything that applies directly to my situation before. From what I've been able to figure out, however, I have to do something like this:
Place a Panel and a ModalPopupExtender on the page inside an UpdatePanel.
Build a custom WidgetManipulator user control that has a WidgetID property. Put this in the Panel, along with a couple OK/Cancel buttons.
In Javascript on the page, attach a click handler to each widget in the ListView that triggers a postback on the UpdatePanel.
On the UpdatePanel_Load event on the server, display the ModalPopup and then set the WidgetID propety on the WidgetManipulator to the ID of the clicked widget.
On the OKButton_Click event or CancelButton_Click event on the server, hide the ModalPopup. If OKButton was clicked, call WidgetManipulator.SaveChanges() first.
The part I haven't figured out is: How the heck do I know what widget was clicked on, and how do I pass that back to the server when I refresh the UpdatePanel? Is this even the right approach at all?
If you can use jQuery instead you could do something along the lines of these two posts:
Modal Delete Confirmation Version
Two Using jQuery SimpleModal Plugin
Demo
Inserting Content Using
jQuery SimpleModal Plugin Demo
When I need to pass data from client to server in ASP.NET AJAX, I generally use an asp:HiddenField with runat="server". Both can see it freely, but beware potential postback asynchronicity.
Sounds like you need to notify the server the widget was clicked - You may use a Timer to postback; or I'd go with option 5.