Pages

Showing posts with label How to. Show all posts
Showing posts with label How to. Show all posts

Friday, February 26, 2016

The Annoying mouse buttons flip!



Good Morning :)

The Annoying mouse buttons flip I've been facing since the upgrade to windows 10 on my laptop was literarily driving me nuts!!

Every time I log in to my work VPN network and start the Remote Desktop Connection (RDC), I pray to have the right mouse configurations on right button settings.. but end up every time with a flipped settings that I have to switch it once I'm in and revert it back once I'm about to logoff or when I login physically from my office the next day..

was it annoying .. Hell ya !!

googled it a lot, and wasn't lucky until today :D

a simple edit in registry and VOILA...

  1. Open Registry Editor ( Type "regedit" in Run window)
  2. Go to "Computer\HKEY_CURRENT_USER\Control Panel\Mouse"
  3. Edit the value of the "SwapMouseButtons" : revert it to "0" if it was changed to "1"
  4. Restart! and that's it .. Problem Solved
Happy Friday

Monday, September 21, 2015

How-To: Fix Cisco VPN Client issues in Windows 10

Trying to have Cisco VPN Client to work after upgrading to Windows 8 been an annoying headache to lots of people and now the same goes for Windows 10 :(  .. Cisco VPN Installer never completes, aborting with the error: "error 27850 (Unable to manage networking component. Operating system corruption may be preventing installation)."

Thanks to google and Eric M's post after God's Guide, here are the steps to get the Cisco VPN Client to work in Windows 10.

1 Ensure you are using the latest version of Cisco VPN Client

At the time, the most recent version and the one I used was 5.0.07.0440.

2 Pre-Install the DNE software

The issue seems to be with Cisco's installer not being able to make the required changes to fully add the DNE driver to the system. You can avoid that by having it pre-installed. You can get this from Citrix's site here:


About 1/2 way down, you will find the "Other DNE Problems" with links to 32-bit and 64-bit versions.


3 Install the Cisco VPN Client

Once the DNE is installed, the Cisco software should now work correctly... Install it now.

4 More issues: Reason 442: Failed to enable Virtual Adapter

Like in previous versions of Windows, the registry key for the driver ends up with information in front of the name that prevents the VPN software from enabling the Virtual Adapter. This can be fixed by correcting the registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\CVirtA\DisplayName
It will be preceded by something like "@oemX.inf,%CVirtA_Desc%;" remove this so the line entry reads similar to "Cisco Systems VPN Adapter for 64-bit Windows"


 Now you should be able to add your VPN Connection details and get connected. Hope this works with you.
UPDATE:
Had some issues with an updated version of windows 10.. installed global VPN Client from http://help.mysonicwall.com/Applications/vpnclient/  and then CISCO VPN Client installed without any issues :)

References

Monday, March 16, 2015

How-To remove HTMLTags to display plain text using XSLT


In this post i will be showing how you can use XSLT to strip out HTML tags from HTML data sources (Rss, sharepoint list item, database field ... etc) and display plain text

Below is the function to remove HTML tags:

  <xsl:template name="removeHtmlTags">
    <xsl:param name="html"/>
    <xsl:choose>
      <xsl:when test="contains($html, '&lt;')">
        <xsl:value-of select="substring-before($html, '&lt;')"/>
        <!-- Recurse through HTML -->
        <xsl:call-template name="removeHtmlTags">
          <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$html"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

You can see that the function name is removeHtmlTags which accepts one argument / parameter named as html which is my Description field that contains HTML Tags.
Logic is simple, its a recursive function which finds for '&lt;' that is '<' means starting of any HTML Tag and take out the substring after this '<' Tag using substring-before() function as substring-before($html, '&lt;') and again call the function with the rest of the string left after  '&gt;' that is '>' Tag.

This is how this function will be called:

    <xsl:template name="RssCell">
        <xsl:variable name="pureText">
            <xsl:call-template name="removeHtmlTags">
                <xsl:with-param name="html" select="DescriptionField" />
            </xsl:call-template>
        </xsl:variable>

        <div height='40' class='blog_text'>
            <xsl:value-of disable-output-escaping="yes"  select="substring($pureText, 0, 175)"/>
        </div>
    </xsl:template>

One Variable is declared as pureText. removeHtmlTags() function will strip out the HTML Tags and return the Plain Text values in this pureText variable.
I am passsin DescriptionField that is my DB Field with HTML Tags.

Finally, I am displaying max 175 chars of Plain Text as substring($pureText, 0, 175) inside a DIV.

Thats It!


Reference

Thursday, October 9, 2014

How To: Raising Custom Events from Custom .Net UserControls

In the last few days I've been searching books and websites to get back to "object oriented programming" I remember in my head from back time in college java and C++ courses about classes, event handling, delegates, inheritance .. etc but can't seem to get what I have in mind done in current C# development work requirements as custom electronic request forms automation, built with custom .net controls in SharePoint environment to be reused among them all when needed.

in this post I'll be showing you how to raise an event from within usercontrol's native controls events and handle it with a custom code in webpage code file hosting the usercontrol.

watching Kudvenkat's YouTube videos below helped a lot to understand the event handling technique by following the 5 steps to raise an event from the usercontrol

  1. Step 1: Create XxEventArgs class that will contain the event data.
  2. Step 2: Create XxChangedEventHandler delegate that raises this event. 
  3. Step 3: Create XxChanged event that is a variable of type delegate.
  4. Step 4: Create a protected virtual method to raise the event that enables the derived classes to do some additional work before the event can be raised. 
  5. Step 5: Finally raise the event, whenever the usercontrol's controls is changed.
Let's say, we want to raise TimeChanged event every time the usercontrol ( from the previous post ) controls values changes. i.e, when hours TextBox's Text is changed, minutes TextBox's Text is changed, or time DropDownList's Index is Changed.
  1. Step 1: Create TimeChangedEventArgs class that will contain the event data:


    public class TimeChangedEventArgs : EventArgs
    {
        private string _ucTimeValue;

        // Constructor to initialize event data
        public TimeChangedEventArgs(string ucTimeValue)
        {
            this._ucTimeValue = ucTimeValue;
        }

        // Returns ucTimeValue   
        public string UcTimeValue
        {
            get { return this._ucTimeValue; }
        }
    }


  2. Step 2: Create TimeChangedEventHandler delegate that raises this event.


    public delegate void TimeChangedEventHandler(object sender, TimeChangedEventArgs e);

  3. Step 3: Create TimeChanged event that is a variable of type delegate inside the usercontrol's class:


    public
    event TimeChangedEventHandler TimeChanged;

  4. Step 4: Create a protected virtual method to raise the event that enables the derived classes to do some additional work before the event can be raised.
    Checking if TimeChanged is null is a good practice as it will give error message in cases when you don't need to have a custom event handling in usercontrol's host. 

    protected
    virtual void OnTimeChanged(TimeChangedEventArgs e)
        {
            if (TimeChanged != null)
            {
                TimeChanged(this, e);
            }
        }

  5. Step 5: Finally raise the event, whenever the usercontrol's controls is changed:
    by assigning the following event handlers to the controls and then raising the event 
    1. When hours TextBox's Text is changed:


        protected void hourTxtBx_TextChanged(object sender, EventArgs e)
          {
               OnTimeChanged(new TimeChangedEventArgs(this.hourTxtBx.Text + ":" + this.minTxtBx.Text + " " + timeDDL.SelectedValue));

          }

    2. When minutes TextBox's Text is changed:


        protected void minTxtBx_TextChanged(object sender, EventArgs e)
          {
               OnTimeChanged(new TimeChangedEventArgs(this.hourTxtBx.Text + ":" + this.minTxtBx.Text + " " + timeDDL.SelectedValue));

          }

    3. When time DropDownList's Index is Changed:


        protected void timeDDL_OnSelectedIndexChanged(object sender, EventArgs e)
          {
              OnTimeChanged(new TimeChangedEventArgs(this.hourTxtBx.Text + ":" + this.minTxtBx.Text + " " + timeDDL.SelectedValue));

          }

Now to consume the usercontrol custom event:
  1.  Step 1: Create an event handler method. The method signature must match the signature of the "TimeChangedEventHandler" delegate.


    protected
    void fromTimeUC_OnTimeChanged(object sender, TimeChangedEventArgs e)
        {
            string errMsg = "";
             
            timeErrLbl.Text = (!checkTime(e.UcTimeValue , out errMsg)) ? errMsg : "";
            timeErrLbl.Visible = (!string.IsNullOrEmpty(errMsg))
        }

  2. Step 2: Register the created event handler method to the usercontrol OnTimeChanged event:


  <uc1:jpTimeChooser35UC OnTimeChanged="fromTimeUC_OnTimeChanged" ID="fromTimeUC"  runat="server" />




That's it ..  hope it was helpful :)

Reference:

How To: Using asp.net Validation Controls to be used with Custom Usercontrols

To use asp.net Required Field Validator, Range Validator ..., etc you must have a ValidationProperty attribute that specifies which value from your custom user control the validation controls to be validated validate.

So.. In your custom usercontrol  class add the ValidationProperty attribute and a property that returns the data in a format that is suitable for the validation controls.

Usercontrol
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="jpTimeChooser35UC.ascx.cs"
    Inherits="jpTimeChooser35UC" %>
<table cellpadding="0" cellspacing="0" dir="rtl" style="text-align: center;">
            <tr>
                <td>
                    <asp:TextBox ID="minTxtBx" MaxLength="2" runat="server" Width="30px" CssClass="tblField" Text="30" Style="text-align: center" >
                    </asp:TextBox>
                </td>
                <td>
                    :
                </td>
                <td>
                    <asp:TextBox ID="hourTxtBx" runat="server" MaxLength="2" Width="30px" CssClass="tblField" Text="07" Style="text-align: center" >
                    </asp:TextBox>
                </td>
                <td style="padding-right: 5px">
                    <asp:DropDownList ID="timeDDL" CausesValidation="false" Font-Size="10pt" Width="50px" runat="server" CssClass="tblField">
                        <asp:ListItem Selected="True">ص</asp:ListItem>
                        <asp:ListItem>Ù…</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr style="color: Gray; text-align: center; padding: 0px; font-family: Tahoma; font-size: 9pt;">
                <td>
                    دقيقة
                </td>
                <td></td>
                <td>
                    ساعة
                </td>
            </tr>
        </table>
        
 
Preview 



Usercontrol's Code:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
[ValidationProperty("TimeValue")]
public partial class TmeChooser35UC : System.Web.UI.UserControl
{
    public object TimeValue
    {
        get
        {
            string TimeString = this.ucHours+":"+this.ucMinutes+" "+this.ucTime;
            if (TimeString == ": Øµ")
            {
                return "";
            }
            else
            {
                return TimeString;
            }
        }
    }
    public string ucMinutes
    {
        get { return minTxtBx.Text.ToString(); }
        set { minTxtBx.Text = ucMinutes; }
    }
    public string ucHours
    {
        get { return hourTxtBx.Text.ToString(); }
        set { hourTxtBx.Text = ucHours; }
    }
    public string ucTime
    {
        get { return timeDDL.SelectedValue.ToString(); }
        set { timeDDL.SelectedValue = (timeDDL.Items.Contains(new ListItem(ucTime))) ? timeDDL.SelectedValue = ucTime : ""; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

 
and then use a RequiredFieldValidator and the Usercontrol  in a WebPage 
<%@ Page Language="C#" Culture="ar-sa" Title="Untitled Page" %>
<%@ Register Src="jpTimeChooser35UC.ascx" TagName="jpTimeChooser35UC"   TagPrefix="uc1" %>

<uc1:jpTimeChooser35UC ID="fromTimeUC"  runat="server" />
<asp:RequiredFieldValidator runat="server"ErrorMessage="ERROR_MESSAGE" 
ID="RequiredFieldValidator1" ControlToValidate="fromTimeUC" 
SetFocusOnError="True"></asp:RequiredFieldValidator>

<asp:Button ID="submitBtn" runat="server" Text="submit"
CssClass="tblButtons" Visible="true" OnClick="submitBtn_Click"/>
Preview 


  













That's It .. Hope this was helpful :)

Reference: Microsoft Support #310082