Please check the below screen
When the user clicks the first dynamic menu , then the user clicks the context menu the server side event(item_click) is executed.As soon as the user clicks the user clicks the second dynamic menu and then again clicks the context menu first time the server side event (item click) is not executed.After selecting 3-4 times again the context menu hits the server event.
The dynamic menu are filling inside repeater.The code of radcontext menu is below in aspx page:-
the whole inner content changes with the click of every dynamic control menu.This is attached inside placeholder.
Please let me know why the server event of context menu stops firing once we go inside one dynamic control but the client event fires.
-Sulekha
Probably you do not recreate something right. Make sure to create your dynamic controls in the Page_Init event and to provide the same IDs for them each time. If this is not done, server events tend to fail and even the ViewState may not load properly.
Related
I have two labels one lblEmail1 and two lblEmal2 each has the same context menu strip associated with it. The contextmenustip has one menu item which is "Send Email" when I right click on either label and you select "Send Email" it goes to the same function to process the request which would be to take the value lblEmail1.Text or lblEmail2.Text and start an email. The problem is I can't figure out how to tell which label initiated the request. Any help would be appreciated.
add an event handler for the menu's opened event
Sender will be which of the labels triggered it.
Store that somewhere, the email menuitem's tag property would be good, or a private variable on the form class.
Then in the Onclick of the menu item test and proceed accordingly.
I have an ASP.NET user control with a button, and I want to add it to the page when the user clicks a button from another user control. I have created an event handler to the first user control to handle it from the page and add the second user control to a page. Everything is working normally, but the button on the second user control doesn't respond to the event.
I place the second control on RadAjaxPanel
Note: When I add the second user control at design time its working fine.
All dynamically created controls should be added by the end of Page_Init (though sometimes you can get away with them added by the end of Page_Load).
If you're only adding them based on a button click event then you've done this in the event handers which fire AFTER Page_Init and Page_Load in the lifecycle - This is why your events don't fire and why it works fine when you add at design time.
This is because when a button is clicked on the second user control - the whole page lifecycle starts again. The page goes through Page_Load and Page_Init first and your control doesn't get loaded here. So, when the page lifecycle handles the "handle postback events" part, the control no longer actually exists, so the event doesn't fire.
Conversely, when you add at design time, the control exists in Page_Init and Page_Load so is able to handle the postback events from the user control because it already exists in the control tree - if this makes sense.
You need to think how you can restructure so they're added by the time Page_Load has finished at the very latest or it won't work. Without code samples or more detail it's hard to suggest exactly how you might do this. One possibility would be to set it visible instead of loading it outright - but if the control does some 'heavy lifting' on load like database hits or API calls then this might not be suitable for you.
I did something similar. What I did was to load some controls dynamically based on a selection from a DropDownList. If you have a method which loads the control for you, let's call it LoadControls(), then you can do something like this:
DropDownList_Click {
ViewState("LoadControls") = true;
LoadControls()
}
By setting the ViewState variable, you can then indicate Page_Load to load the controls on future postbacks:
Page_Load {
if (ViewState("LoadControls") == "true")
{
LoadControls();
}
}
This has the effect of then loading the control on-the-fly when the event first happens, and then at future times in the lifecycle.
I have a button, contained in a panel, with a click event, that works fine. However when a users presses another button, I need to move this button into another panel (this is actually a panel with a modalpopupextender), so I this code to do so:
newPanel.Controls.Add(buttonPanel)
It all get's moved and looks fine. However now when the button is clicked it doesn't fire the associated event. I have tried re-adding the event in the page_init, with this code
((Button)this.FindControl("serverModalSave")).Command += new CommandEventHandler(modalSave_Click);
But with no luck. How can I get this button to fire it's click event when moved, and why does it stop working when it's moved?
EDIT:
This Button needs to be added to a panel specified by the user at run time, so there is not a way to determine where the button will go in advance.
I could instead of moving this button, create a new one, but because this button is not created in the page_init I am having issues getting that to fire an event either.
Instead of moving the button, have another button on the other panel set to hidden.
Hide the button you wanted to move and show the hidden one when needed.
Moving the control changes the naming hierarchy and now the button can't be found and the click event can't fire.
This is due to how the page life cycle works. Here is a good (if somewhat dated) article about how view state works - if you understand this, you will understand what went wrong.
If you are creating the button in the new panel, when this button is then clicked do you re-create it in the postback ?
You must re-create all controls on each postback see here
When the user clicks on a tab, I want to fire the radconfirm window to ask them if they want to proceed. Now, I cancel the event, fire radconfirm, and in the callback, if successful, I'm trying to explicitly postback to show the new tab. I tried doing:
//In tabSelecting event on client
e.get_tab().select(); //to select the new tab because I canceled the selection earlier on
sender._postback(e.get_tab()); //to perform the postback
The RadMultiPage gets updated to the new tab's content, but the RadTabStrip does not show me the new tab selected. I see the old tab selected with the new tab's content.
Any ideas?
Thanks.
If you get your hands on the client object of the clicked tab, you can set is as selected using the set_selected method from the client API (see here).
Because I was attaching to tabSelecting, I need to add a boolean in the component to prevent the cancelling of the event the second time, because setting the selected tab was also firing tabSelecting event. That was the fix.
Is it possible to add instances of the same user control when an "add" button is clicked and maintain ViewState?
The user interface here is similar to the Gmail file-attachment process, where the user can click "attach another file" and another file upload box appears.
My page is surrounded by an UpdatePanel. I am able to get 1 control to load, but the button's click event fires after the Placeholder_Init method. I tried storing an integer in the ViewState that kept track of the number of user controls that should be rendered, but the Init method is also fired before the ViewState is restored.
Thanks!
Adding multiple controls dynamically is easy in ASP.NET. Let's say you have a panel named Panel declared in your ASPX file and you have a custom control called MyControl.
In your Page_Load function (or indeed pretty much anywhere), add something like the following:
for (int i = 0; i < NumberOfAttachments; i++) {
Panel.Controls.Add(new MyControl());
}
This works for UpdatePanels, too, but you'll need to call the .Update() function to get it to update on the client side if you don't have it to update on child postback.