Friday, November 25, 2011

How To validate Email ID a Form in ASP. Net.

<script language="javascript" type="text/javascript">
function validate()
{
if (document.getElementById("<%=TextBox1.ClientID%>").value=="")
      {
                 alert("Name can not be blank");
                 document.getElementById("<%=TextBox1.ClientID%>").focus();
                 return false;
      }
      
      if(document.getElementById("<%=TextBox2.ClientID %>").value=="")
      {
                 alert("Email id can not be blank");
                document.getElementById("<%=TextBox2.ClientID %>").focus();
                return false;
      }
     var emailPat= /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
     var emailid=document.getElementById("<%=TextBox2.ClientID %>").value;
     var matchArray = emailid.match(emailPat);
     if (matchArray == null)
    {
               alert("Your email address seems incorrect. Please try again.");
               document.getElementById("<%=TextBox2.ClientID %>").focus();
               return false;
    }
    if (document.getElementById("<%=TextBox3.ClientID%>").value=="")
      {
                 alert("Contact Number can not be blank");
                 document.getElementById("<%=TextBox3.ClientID%>").focus();
                 return false;
      }
     var digits="0123456789";
     var temp;
     for (var i=0;i<document.getElementById("<%=TextBox3.ClientID %>").value.length;i++)
     {
     temp=document.getElementById("<%=TextBox3.ClientID%>").value.substring(i,i+1);
     if (digits.indexOf(temp)==-1)
      {
      alert("Please enter correct Contact Number");
      document.getElementById("<%=TextBox3.ClientID%>").focus();
      return false;
      }
     }
      if(document.getElementById("<%=TextBox5.ClientID %>").value=="")
    {
      alert("City can not be blank");
     document.getElementById("<%=TextBox5.ClientID %>").value;
      document.getElementById("<%=TextBox5.ClientID %>").focus();
      return false;
    }
      if(document.getElementById("<%=TextBox6.ClientID %>").value=="")
    {
     alert("Password can not be blank");
     document.getElementById("<%=TextBox6.ClientID %>").value;
     document.getElementById("<%=TextBox6.ClientID %>").focus();
      return false;
    }
    if(document.getElementById("<%=TextBox7.ClientID %>").value=="")
    {
     alert("Please Re-Enter Password ");
   document.getElementById("<%=TextBox7.ClientID %>").value;
   document.getElementById("<%=TextBox7.ClientID %>").focus();
    return false;
    }
     return true;
}
</script>

Thursday, November 24, 2011

Limit no of character in textbox with count in Asp.net using javascript

<script type="text/javascript">
 {if (field.value.length > maxlimit)


{return false;</script>

}
}
function textCounter(field,maxlimit)


protected void Page_Load(object sender, EventArgs e)"onkeydown", "return textCounter(this, 5)");"onkeyup", "return textCounter(this, 5)");"onmousedown","return textCounter(this, 5)");"onmouseup","return textCounter(this, 5)");"onblur", "return textCounter(this, 5)");
{
txtmaxlen.Attributes.Add(
txtmaxlen.Attributes.Add(
txtmaxlen.Attributes.Add(
txtmaxlen.Attributes.Add(
txtmaxlen.Attributes.Add(

}

Wednesday, November 16, 2011

Spaces are not allowed!

<asp:RegularExpressionValidator ID="rev" runat="server" ControlToValidate="txtBox" 
   
ErrorMessage="Spaces are not allowed!" ValidationExpression="[^\s]+" /> 
<asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="txtBox"  
   
ErrorMessage="Value can't be empty" /> 

Monday, September 26, 2011

Adding more Interactive features to our Video Player.


I promised in the previous topics that I will be adding more “stuff” to each topic that we discussed prior and in this article I want to revisit the previous article where we created a cool Video Player using a button. For those who didn’t read that article please see it here.  Now, remember that the only interactive feature we added was a button click event to play the video but we didn’t include any visuals. So this time around we will add Play, Stop, and Pause buttons.

In future topics we will add a volume slider, and a Seek to Slider buttons, among other things and I will explain these later on, but for now we want to add interactive buttons to our video player, and make it look like the following or whatever cool video player you created last time:
Note: Before I go deeper into this Media API discussion, I want to make sure that the reader understands that this is an introductory topic to beginners of Expression Blend and WPF.
Now that we have taken care of the disclaimerJ, let’s discuss a little bit about the Media API and how it works in Expression Blend.  Expression Blend supports audio and video file types that Microsoft Windows Media Player 10 and above supports.  This means in order to work with media in Expression Blend, you must have Windows Media Player 10 OCX or above installed on your computer. As you may have noticed in the previous article when you add a MediaElement in Expression Blend the Media pane is added:

We did touch a little bit about the MediaElement and MediaPlayer in the previous topic, and these two can be used to present video, video with audio, and audio. There are however, used to target different scenarios although both rely on the Microsoft Windows Media Player 10 OCX and above for media playback. Since MediaElement is a UIElement that it supported by the Layout System, it can be consumes as content by many controls. On the other hand MediaPlayer is designed for Drawing object and lacks layout support, therefore media loaded using MediaPlayer can only be presented using a VideoDrawing or directly interacting with DrawingContent. As you have already noticed in the previous topic when you insert a MediaElement in Expression Blend, the Insert feature adds an audio or video file to the artboard wrapped in a MediaElement control as long as you’re using one of the supported media types.
Enough about the conceptual stuffJ, let’s jump in and do some designing and add more controls to our previous video player.
  1. Open the previous project just before we added a video to the “cool” button we designed. We are not making any changes to the video this time but you should have a video linked to the Video Player.
  2. Add a rectangle to the artboard with a solid white Fill and no Stroke. This will be our Play button.
  3. Convert the rectangle to a path (right click on element):

4.     Using the Direct Selection tool drag one corner of the converted path halfway towards the other corner:
Make sure you have a straight line.
5.    Use  the Transform panel to rotate the path (rectangle) 45%, and also reduce the size of the path to 13×14 (W x H):

6.    Next, let’s create a Stop button. Add another rectangle with whatever Fill you want and no Stroke.  Also reduce the size to 10×12 (WxH).
7.   Let’s move on to the Pause button, add two rectangles (2×12) in size. Group Into a Grid the two rectangles and name the grid “Pause”. Now you should have all three buttons as follows: Play, Stop, Pause:

Now, we could simply add a few lines of code to these three buttons and make them interactive with our video but we are not going to do that yetJ! Remember, we are supposed to be creating cool things in Expression Blend!
8.   So the next step we want to do is to duplicate or copy the cool button we created in step 15 and reduce the size to say 85×47 (WxH). Position this smaller button on the center of the video player or wherever you like.
9.  Next, edit the ButtonStyle of that button (Video Player) you copied above and add the “Play” element you created above.  Mine looks like this:

10.  Repeat the above step for the Stop and Pause buttons. Tip: simply copy the button style and edit the Template if you want to apply the same style to all buttons. If on the other hand you want to apply a different style, simply create a new style from the base class:


Tip: Remember when aligning your elements, the Layout and the Transform panels are your best friends!
11.   Once you’re done with the layout your Play, Stop and Pause buttons should look like the following or something similar:

Now, positioning this on my video player:

12.  Next, let’s add a few simply lines of code to make our buttons interactive. In my LayoutRoot, I have the following:

Now, we want to move the button click play event we created last time to the Play button we just created:


13.  Next wire the Stop and Pause buttons using simple click events:

Note: There are better ways of wiring this other than what we just did but that will be for another topic in the future. I want to keep it as simple as possible to none coders.
14.  Build and test you application, you should be able to Play, Stop and Pause the video:

Conclusion
That’s it folks for nowJ! We have seen how Play, Pause and Stop methods can be used to control media. In the next few topics we will cover other ways of interacting with media, for instance, using triggers.  Remember again, this is an introductory topic to new Expression Blend/WPF users, and people who are interested in learning how to use Expression Blend for designing UserInterfaces (UIs).  Hope this helps someone!

Friday, September 23, 2011

LINQ WITH DELEGATES CONCEPTS

Normal query string:
===================

static void Main(string[] args)
        {
            string[] names = { "chitharans", "naga", "ravi", "praveen", "chith", "hello", "welcome" };
            IEnumerable<string> query123 = from sss in names where sss.Length >= 4 orderby sss descending  select sss.ToUpper();
            foreach (string item in query123)
                Console.WriteLine(item);
            Console.ReadKey();
        }


Funtion  using query string:
=========================================

  static void Main(string[] args)
        {
            string[] names = { "chitharans", "naga", "ravi", "praveen", "chith", "hello", "welcome" };
            Func<string, bool> one = sss => sss.Length >= 4;
            Func<string, string> two = sss => sss;
            Func<string, string> three = sss => sss.ToUpper();
            IEnumerable<string> query123 = names.Where(one).OrderBy(two).Select(three);
          
            foreach (string item in query123)
                Console.WriteLine(item);
            Console.ReadKey();
        }

Delegates using query string:
============================

 static void Main(string[] args)
        {
            string[] names = { "chitharans", "naga", "ravi", "praveen", "chith", "hello", "welcome" };
            Func<string, bool> one = delegate(string sss)
            {
                return sss.Length>=4;
            };
            Func<string, string> two = delegate(string sss)
            {
                return sss;
            };
            Func<string, string> three = delegate(string sss)
            {
                return sss.ToUpper();
            };



           
            IEnumerable<string> query123 = names.Where(one).OrderBy(two).Select(three);
         
            foreach (string item in query123)
                Console.WriteLine(item);
            Console.ReadKey();
        }

Thursday, September 15, 2011

Creating Visual State Manager(Media Player)

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SLVSMMediaPlayer
{
    public partial class VSMPlayer1 : UserControl
    {
        public VSMPlayer1()
        {
            // Required to initialize variables
            InitializeComponent();
            Loaded +=new RoutedEventHandler(VSMPlayer1_Loaded);
        }
      
        void VSMPlayer1_Loaded(object sender, RoutedEventArgs e)
        {
          
            LayoutRoot.MouseEnter +=new MouseEventHandler(LayoutRoot_MouseEnter);
            LayoutRoot.MouseLeave += new MouseEventHandler(LayoutRoot_MouseLeave);
            button.Click += new RoutedEventHandler(button_Click);
            button1.Click += new RoutedEventHandler(button1_Click);
           
           
        }

        void button1_Click(object sender, RoutedEventArgs e)
        {
            //throw new NotImplementedException();
            mymedia.Pause();
        }

        void button_Click(object sender, RoutedEventArgs e)
        {
           // throw new NotImplementedException();
            mymedia.Play();
        }

        void LayoutRoot_MouseLeave(object sender, MouseEventArgs e)
        {
            //throw new NotImplementedException();
            VisualStateManager.GoToState(this,"MouseLeave", true);
        }

        void LayoutRoot_MouseEnter(object sender, MouseEventArgs e)
        {
            //throw new NotImplementedException();
            VisualStateManager.GoToState(this, "MouseEnter", true);
        }
    }
}

Thursday, September 8, 2011

Silverlight and the layout management. (Grid, Canvas, StackPanel and dock panel)






If you have done any Silverlight development, then you are familiar with the Canvas, the Grid and the StackPanel.
All 3 containers are unique in their own way. But they all have some limitations/drawbacks. Let's see:
1: The Canvas:
<Canvas Background="Blue">
   <TextBlock Height="50" Width="50" Canvas.Left="15" Canvas.Top="15" />
</Canvas>
I don't want to pixelate my items.
2: The StackPanel: 
<StackPanel>
   <TextBlock Height="50" Width="50" />
   <TextBlock Height="50" Width="50" />  
</StackPanel>
Just not rich enough to do any complex layouts.
3: The Grid:
<Grid Background="Silver">
   <Grid.ColumnDefinitions>
       <ColumnDefinition Width="*2" />
       <ColumnDefinition Width="*1" />
   </Grid.ColumnDefinitions>
   <Grid.RowDefinitions>
       <RowDefinition Height="50" />
       <RowDefinition Height="100" />
   </Grid.RowDefinitions>
   <TextBlock Height="50" Width="50" Grid.Row="1" Grid.Column="1"/>
</Grid>
Yes, I can define a very complex layout using the Grid. But I am still required to place my items inside "a" cell by specifying
the Grid.Row and Grid.Column attributes on each individual item. I also need to decide, how may rows and columns my page has.
This just does not feel natural.
To address this, Developer Express is working on a special LayoutControl container that will eliminate these hassles. All you have to do is specify where you want
your items placed. Left, Right, Top or Bottom.
<DockedLayoutControl x:Name="layoutItems" DockedLayoutControl.Dock="Client">
            <TextBlock Text="My Top Text" DockedLayoutControl.Dock="Left"/>
            <TextBlock Text="My Bottom Text" DockedLayoutControl.Dock="Bottom"/>
</DockedLayoutControl>
Here is a screen shot of a layout done using a DockedLayoutContro