How to tell which control a contextmenustip is associated with? - c#

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.

Related

Make Button Ignore ENTER key pressed c#

im building a page using ASP.NET, however, the first element of my page is a Button and there are other elements below it, however, if the client types something and it shows a confirmation box, and he presses ENTER key, it activates the first button at the page.
I tried to change the tab order does not work.
sorry for noob question xD
Have you tried setting UseSubmitBehavior=False on the first button?
Don't handle the click event. Handle the MouseClick event instead. So whatever code is in click, simply move to the MouseClick event

Issue in firing the server side event of rad context menu

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.

ASP:Button OnClick event not firing in one specific instance

What I have is a popup defined within a user control, that is opened within a taskbar user control, which is attached to a master page, such that:
MasterPage.TaskBarUC.PopupUC
Within the popup, there are two buttons, one to save what the user is trying to do within a database, and one to cancel. I have some codebehind that does the work when the user clicks either button.
So every page has the taskbar, and they can click a button on the taskbar to access the popup and save the information. It works perfectly. However, there is one specific page within the site that needs to access the same popup from a button located on the page, as well as from the taskbar.
The button works, and it opens the popup, but for some reason, and only in this case, the "Save" button doesn't activate my codebehind. It DOES perform the validation that I have it do though. What is also weird is that the cancel button, which also activates some codebehind, does do what its supposed to.
I tried putting a breakpoint right at the beginning of my "Save" event handler, and it never reaches it. Its as if the button is only validating, and completely ignoring its OnClick event.
.aspx
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click"
ValidationGroup="Validation" />
I guess what happens is that the validation process has failed, which cancel the handling of the Button.Click event.
To check this possibility try to set the value of the Button.CausesValidation property to false and see if the Button.Click handling is going to continue or not.
Button.CausesValidation property to false worked for me. I am using required field validator for different button. I think this could stop post back even for all other button click events (serverside).

RadTabStrip On Click Show Prompt

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.

Displaying MessageBox when disabled menu item is clicked

I want to display a message box when any person clicks on the menu item which is not enabled I have tried the following coding but it is not displaying the message box.
Coding:
private void updateFineDetailsToolStripMenuItem_Click(object sender, EventArgs e)
{
if (updateFineDetailsToolStripMenuItem.Enabled == true)
{
frmUpdateFineDetails objUpdateFineDetails = new frmUpdateFineDetails();
objUpdateFineDetails.MdiParent = this;
objUpdateFineDetails.Show();
}
else if (updateFineDetailsToolStripMenuItem.Enabled == false)
{
MessageBox.Show("Unauthorized Person");
}
}
By default I have set the enabled status to false and when the form loads I am checking whether the user is administrator, if the user is admin then this menu item will be enabled for all other user who logs into the application the above menu item has to be disabled.
Please note that the above coding does not generate any error, but it does not even display the messagebox as unauthorized person.
Can anybody help me out in performing this task?
Thanks in advance!
The whole idea of disabling a menu item or a button is to prevent the user from interacting with it. Typically the control will also be rendered in a way so that this becomes clear to the user. If you want to prevent the user from taking certain actions, for instance based on whether the user is an administrator or not, you can use one of three approaches:
Keep the control enabled and inform unauthorized users that the function is not available if he or she invokes it
Disable the control
Hide the control
In the later two cases there is no interaction, since the user cannot invoke the command. I usually tend to prefer to hide the command, if the access to it is role based (meaning that if I don't have access to the command when I start the application, it will not happen at any point while running it), or disabling it if the availability of the command is related to data state.
As I understand, a disabled menu item does not raise Click events.
If you need to display the error message then enable the menu item.
If admin clicks then default action occurs and if other users click show a message box and prevent the default action.
From your code I think you can do this just by enabling the menu item.
Disabling a menu item isn't a cosmetic display issue, it does just what you'd expect from the term - it disables the menu item.
When disabled, the menu item is effectively inert - it will not raise the click event, and there's no (straightforward) way to make it do so.
I can guess at your motivations - to explain to your users why the particular menu item is unavailable to them - but you'll need to find a different approach, one that works with the system, not against it.
Some possible approaches ...
Leave the menu item disabled, allowing the user to select it - you can then make a role based choice on how to handle the event.
Disable the menu item and provide feedback elsewhere in your UI telling the user what level of access they have.
Display a tooltip with the reason for disabling the control
Leave the menu item enabled, but change it's display to look inactive (this is hard to achieve 100%); this will allow the events to fire and your handler to be invoked
Create a separate "Explain" menu item, perhaps on the "Help" menu; when invoked, all disabled menu items become enabled, and will explain to the user why the command is unavailable.
Some systems display a line of help text relevant to the highlighted menu item on the status bar - you could leverage this to explain availability: "Maintain customer details (requires Administrator role)"
a disabled control does not raise Click events. you should simulate that state! for example:
enable menu item
change menu item's forecolor to SystemColors.GrayText
save state of item in item's tag (enable or disable)
if click event raised, first check item's tag
change menu item's forecolor to normal fore color if enabled item.

Categories