Allow checkbox to be disabled in Firefox - c#

So I am working on cross-browser code right now. I have checkboxes, that disable after certain functions are called, in IE but not in Firefox & Chrome.
I looked into the code and I see that when rendered in Firefox, the disabled tag is placed on the td which is why it works in IE and not the other browsers.
Is there a way in asp.net to disable the cell or checkbox and have it render properly in Firefox, Chrome, etc?
Here is my function where enabled = false
protected void FilterCheckBox(object sender, ASPxGridViewTableCommandCellEventArgs e)
{
if (ExecContractGridView != null)
{
try
{
if (ExecContractGridView.GetRowValues(e.VisibleIndex, "UnionExecutedBy") != null)
{
if (!string.IsNullOrEmpty(ExecContractGridView.GetRowValues(e.VisibleIndex, "UnionExecutedBy").ToString()))
{
e.Cell.Enabled = false;
}
}
}
catch (Exception ex)
{
ApplicationLog.Exception(this, ex);
}
}
}

To do this properly you want to find the checkbox control and set disabled = "disabled".
You can do so on the client side using JavaScript or a library like jQuery. Or, in your code above, once you have e.Cell you can locate the CheckBox control and set it to Enabled = false.
To further clarify, e.Cell contains a CheckBox control as one of its child controls. So you could do:
var control = e.Cell.FindControl("SomeCheckBoxControl") as CheckBox;
if (control != null)
control.Enabled = false;

Related

maintaining focus in user controls Windows application

I am having a windows application using c#. I have created a form frmMain which loads when user logs in. There are 4 options for the user like Customer Creation, Supplier Creation, Employee Creation, User Creation
This works fine.
The issue arises with focus. When the user loads Customer user control and filling in some data and let's suppose user is somewhere on 4th control (Textbox/Combobox or any other Windows Forms input control) and suddenly he clicks on CreateUser, then CreateUser control loads, but the focus remains on the 4th control in Customer user control.
What I want is to set focus on the current user control where user left it from else if it is newly loaded set focus on default control.
Please check the code which I am using,
// this method gets called if the form was opened earlier
private void ShowOpenForm(ControlItem _item)
{
try
{
//Get item from menu
ControlItem _menuI = null;
foreach (ToolStripmenuI menuI in tsmenuWindow.DropDownItems)
{
_menuI = (ControlItem)menuI.Tag;
if (_menuI.Control.Name.ToLower() == _item.Control.Name.ToLower())
{
break;
}
_menuI = null;
}
if (_menuI != null)
{
WmenuI_ClearAllSelection();
for (int index = 0; index < PnlUserCtrl.Controls.Count; index++)
{
Control ctl = PnlUserCtrl.Controls[index];
if (ctl.Name.ToLower() == _menuI.Control.Name.ToLower())
{
ctl.Visible = true;
ctl.BringToFront();
break;
}
}
WmenuI_SetCurrentItemChecked(_menuI);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//User can navigate to opened items from menu as well
private void WindowMenuItem_Click(object sender, EventArgs e)
{
try
{
ControlItem _item = (ControlItem)((ToolStripMenuItem)sender).Tag;
WmenuI_ClearAllSelection();
for (int index = 0; index < PnlUserCtrl.Controls.Count; index++)
{
Control ctl = PnlUserCtrl.Controls[index];
if (ctl.Name.ToLower() == _item.Control.Name.ToLower())
{
ctl.Visible = true;
ctl.BringToFront();
if (ctl is BaseControl)
{
((BaseControl)ctl).SetFocus(); // This sets the focus to default textbox
}
break;
}
}
WmenuI_SetCurrentItemChecked(_item);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
But this set focus on the default textbox. Not on the control from where user moves to other user control.
It's a good practice to supply some code in your questions for the sake of getting better answers.
You can manually manipulate focus as you want using SetFocus() method. For your question I believe you can have a object of type Control then you can set it to default control you want to focus on. Then you handle all GotFocus methods of your controls and set the value of that object.
Whenever you want focus restored to last item you can call [your object].SetFocus().
This is just an idea. See if it helps.

paste plain text ajax custom editor chrome issue

I used below code to paste plain text in my Ajax Custom Editor. It works fine with IE and Firefox. but chrome got screwed.
please help me!
Also, is there a way to access custom editor buttons via c# code, to apply events or get set values
Sys.Application.add_load( function ()
{
editor = $find('<%=Myeditor.ClientID%>'); // Editor's ID="myEditor"
if (editor != null) {
var editPanel = editor.get_editPanel();
editPanel.set_noPaste(true);
}
//---------------------------------------------------
if (Sys.Extended.UI.HTMLEditor.isIE) {
var designMode = Sys.Extended.UI.HTMLEditor.ActiveModeType.Design;
var designPanel = editPanel.get_modePanels()[designMode];
designPanel.captureInDesign = function (ev) {
if (ev.type == "keydown" && ev.ctrlKey && !ev.altKey) {
// key event
if (String.fromCharCode(ev.keyCode).toLowerCase() == "v") {
this._commonPaste(ev);
return false;
}
}
return true;
}
}
});

Tab Item remains selected WPF

I am using the Tab_SelectionChanged event of TabControl in WPF. It contains 3 tab items. I have to restrict the user to navigate to other tabs i.e Settings and Schedule while work is in-progress on the home tab. While using the event i am facing an issue i.e. If i clicked on settings tab it shows me a popup "You cannot navigate while work is in progress" and when i clicked on schedule tab after clicking on settings tab it shows me the same popup twice. The reason behind this is the Settings tab remains selected.Here is my code for this:
private void tabMHPC_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
TabControl tab = (TabControl)sender;
if (tab.SelectedIndex != -1)
{
if (tab.SelectedIndex != 4 && tab.SelectedIndex != 1 && tab.SelectedIndex != 0)
{
if (scanStatus == "fixing")
{
MessageBox.Show(ApplicationInfo.ApplicationName + " is still busy in fixing issues.Please let the fixation complete.", ApplicationInfo.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Information);
homeTab.IsSelected = true;
}
else
{
MessageBox.Show(ApplicationInfo.ApplicationName + " is still busy scanning issues.Please stop it before you leave the Home tab.", ApplicationInfo.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Information);
homeTab.IsSelected = true;
}
}
else if (tab.SelectedIndex == 0)
{
}
}
}
I want that previous tab item isSelected property gets false when i move on other tabitem.
Instead of handling the SelectionChanged event, you should data bind a property of a suitable type to the TabControl.SelectedItem property:
<TabControl SelectedItem="{Binding YourSelectedItemProperty}" ... />
When you do this, you will then be able to stop the TabItem being changed:
public YourDataType YourSelectedItemProperty
{
get { return yourSelectedItemProperty; }
set
{
if (isOkToChangeTabItem)
{
yourSelectedItemProperty = value;
NotifyPropertyChanged("YourSelectedItemProperty");
}
}
}
The final part of the solution is to set the isOkToChangeTabItem variable to true or false depending on whether it is OK for the user to change the selected TabItem or not.

How to access the scrollbar of a webbrowser control in c#?

My webbrowser control has to be disabled (enabled = false) so that the user can't click in it.
This also disables the access to the scrollbar so I'm thinking about creating another scrollbar next to the control that gets and passes its values from and to the webbrowser's scrollbar.
For that, I need to access the webbrowser scrollbar control. How can I find it ?
webbrowser.Controls.Count returns zero.
Hmm I don't know if there is any method to acccess the scrollbar position programmaticly. You can however, scroll by element name:
private void ScrollToElement(String elemName)
{
if (webBrowser1.Document != null)
{
HtmlDocument doc = webBrowser1.Document;
HtmlElementCollection elems = doc.All.GetElementsByName(elemName);
if (elems != null && elems.Count > 0)
{
HtmlElement elem = elems[0];
elem.ScrollIntoView(true);
}
}
}
Also, see this question for other possibilities.
EDIT:
See question Scrolling WebBrowser programatically sometimes doesn't work

DynamicRadio Button

I'm using C# in VS2005. For my application I need to create four radio buttons. My form looks like:
A(Radio Button)
B(Radio Button)
C(Radio Button)
D(Radio Button)
Submit (Button)
When a user clicks the submit button I need to know which radio button is checked. How can I determine this?
I would add all the radio buttons to a List<RadioButton> which would help you innumerate through them when the submit is checked to figure out which one is checked.
You can use the Checked Property of a RadioButton to see if it is checked:
bool isChecked = radA.Checked;
I often use the following helper function to get exactly the RadioButton which is checked:
public RadioButton GetCheckedRadioButton(Control container)
{
if (container == null) {
return null;
}
else if (container is RadioButton) {
return GetCheckedRadioButton(container.Parent);
}
else {
foreach (Control childControl in container.Controls) {
if (childControl is RadioButton) {
RadioButton radioBtn = (RadioButton) childControl;
if (radioBtn.Checked) {
return radioBtn;
}
}
}
return null;
}
}
Then, you can simply call this function using one of your controls or it's container, and do a switch statement, as such:
switch(GetCheckedRadioButton(radA)) {
case radA:
// radA is checked
break;
case radB:
// radB is checked
break;
}
Personally, I find it less verbose than the usual:
if(radA.Checked) {
//radA is checked
}
else if(radB.Checked) {
//radB is checked
}
If you know for sure that you will only need 4 RadioButtons, then I'd just write code similar to this.
if (Radio1.Checked) ...
if (Radio2.Checked) ...
if (Radio3.Checked) ...
...
If you know that only one of them can be checked at the same time (using a group box or some other mechanism) then you can optimise this by using "else if" instead.
However if there is a possibility that you will need more, this can get wasteful, so I agree with other answers, you should put them in a collection of your choice and use it to loop through them, to see which ones are checked.

Categories