I have a webform which contains some LinkButtons.
When each LinkButton is clicked I want to load a different UserControl.
I also want to do it with Ajax.
I tried it in two ways as described here and here
[Both approaches use an UpdatePanel, the first adds the user control and changes its Visible attribute, the second uses LoadControl function]
Both works (upvoted them!) but I still have a problem-
I can't run javascripts within the user controls...
It doesn't recognize any function
When the user controls were added not dynamically it all went well
The only workaround I found was to move the javascript from the user control to the page but that's not nice...
Also tried this with no luck
Any help will be appriciated
For asynchronous requests use ScriptManager.RegisterStartupScript method
Related
I am adding RadDock control and adding its Item Command events which require to be added in Pag_Init. And adding user controls to RadDock.
My problem is that when I have some post back for a specific control page_Init calls which reloads the controls and every control is re-binded every time. I want to avoid control creation every time. And want the specific control's post back should happen.
If I apply (!IsPostBack) condition in Page_Init then controls are not loaded and page gets empty.
I am stuck.
Any best practice or work around is acceptable.
Thanks in advance.
I don't know the specifics of Telerik's tools, but if they work like regular ASP.NET dynamic controls, you have to add the controls to the control tree on every page load. Populating the controls with data is distinct from adding them to the control tree. If the controls are added correctly so that they are placed in the same way in the control tree as on the previous page visit, and implement ViewState correctly (if needed) the runtime will populate them with data from the posted data and ViewState when a postback occurs.
I added IFrame to RadDock and then gave user control source to IFrame. Now it is working fine, Only the specific control's post back occurs.
Any way, Thanks Jonas
I have a user control that contains a repeater, which in turn is nested in a default.aspx. When a user clicks a specific link on the page, the ajax post function is called which posts data to a method on default.aspx. All good so far! This method then calls a method within the user control, passing in the data, which in turn is used to requery, and rebind the repeater.
For some reason, the page bails when I try to do this last part?
If this seems converluted, it's because it doesn't seem possible in jquery to directly access user control methods.
Many thanks.
Rebinding a repeater control, which is an ASP.NET server control, is done on the server side, not the client side. If you want some grid behavior with ajax I suggest you look at a javascript based grid like for example jqGrid.
I have a page with several user controls in different updatepanels. The user controls includes jquery calls which are used to calculate some values and draw graphs(no server methods are called from jquery).
The problem is that, whatever updatepanel is refreshed, all of the jquery calls are processed again. I think the problem arises because i use pageload methods of the usercontrols to do jquery method calls.
I wonder whether there is a way to stop other user controls from calling their pageload methods or refreshing.
thanks in advance.
maybe this would help...not exactly an answer
when you include custom controls on a page on rendering the controls HTML is included in the page as it is with all JavaScript and css( you can do a View page Source) and check that.
and so in effect there can be 3 pageloads in your page(the page that has the user controls included) in different tags and as such all are getting called when any update panel refreshes.
I have next situation:
I load dynamic controls during on init, and I do correct initialization.
I add dynamic control before postback
I don't add anything later in load
control is loaded and diplayed correctly
I press postback and nothing happens
Why I really don't know.. I tried everything. So control IS properly initialised. __EVENTTARGET shows the same path as the UniqueId of linkbutton that is firing it. All controls in tree have viewstate=true. So, I really don't know what this is not working.
Any idea? I am desperate.. I don't know.. if anyone could suggest me, if not solution, then just things I should check would be very good.
Is this problem just for this page or do you have other pages on the same site with the same problem?
I am assuming that you have the same problem on all pages.
It could be relate do javascript not being allowed. You could try to add the site to local intranet security are, then refresh the page.
Dynamic controls have to be added back to the control tree on each postback for the events to fire.
Dynamically created controls are not part of their container's viewstate, so setting it to TRUE wouldn't have any effect on the situation and are not evaluated until after the on_init call completes anyways.
I would wrap the logic that is populating these dynamic controls in with a conditional check for a postback if(!IsPostBack)
{ //Insert logic here }
If your dynamic controls take input from the user, or need access to their view state, then you would need to move this call to the Page_Load method as this is the point in the page's lifecycle where viewstate is first evaluated.
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.