Wednesday 29 May 2013

ASP.Net : CKEditor | Neha Sharma


Download  CKEditorSourceCode.Zip

Introduction:

This article explains how to create a Text editor in ASP.Net.

Requirement:

1.       Two dll : CkEditor.dll and CKEditor.NET.dll.
2.       CKEditor folder containing all js, css and images.

Code.aspx:

When you are sure about the dlls and CKEditor folder in to your solution explorer then write the below line under page directive line :

<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>

In your page place CKEditar control wherever you want like below:

<div>
   <CKEditor:CKEditorControl ID="CKEditor1" BasePath="/ckeditor/" runat="server">
   </CKEditor:CKEditorControl>
</div>

Finally I design a page for demo with below code lines:

<asp:Panel ID="Panel1" runat="server" Visible="false">
        <asp:Label ID="lblpre" runat="server" Text="" ></asp:Label>
        </asp:Panel>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />

Here I have taken a CKeditor control then a label in a panel and then a button.

Code.cs :

When you finish with design you can see the CKEditor on your page at the desired location but to view the content or text of CKEditor I have taken here a label .On button click below is the code to show text in label:

protected void Button1_Click(object sender, EventArgs e)

    {
        string str = CKEditor1.Text;
        string str1 = Server.HtmlEncode(str);
        lblpre.Text = str1;

       
    }


This is enough to work here, find the source code file here and check it at your side it ll work fine .

Thanks

Friday 24 May 2013

ASP.Net: Text Box Validation Part II | Neha Sharma




Introduction:

In this article I explain some more validations of Text box control in ASP.Net.

Requirement:

Add the below line in head section to create function for validation

<script language="javascript" type="text/javascript">

Then create a function:

function validate()
{
. //function body
.
.
return true;
}

Solution :

1.       Text box Can not be blank :

This kind of validations used to not to allow blank text boxes control in ASP.Net .Add the below function body :

if (document.getElementById("<%=txtName.ClientID%>").value=="")
      {
                 alert("Name Feild can not be blank");
                 document.getElementById("<%=txtName.ClientID%>").focus();
                 return false;
                
      }

Where txtName=Id of a Text Box control

2.       Email id Validation :

This kind of validation used to accept only email id syntax in a text box control in asp.net.Add the below function body :

if(document.getElementById("<%=txtEmail.ClientID %>").value=="")
      {
                 alert("Email id can not be blank");
                document.getElementById("<%=txtEmail.ClientID %>").focus();
                return false;
      }
     var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
     var emailid=document.getElementById("<%=txtEmail.ClientID %>").value;
     var matchArray = emailid.match(emailPat);
     if (matchArray == null)
    {
               alert("Your email address seems incorrect. Please try again.");
               document.getElementById("<%=txtEmail.ClientID %>").focus();
               return false;
    }

Where txtEmail = id of Text Box

3.       Web URL :

This kind of validations used to accept only web url in Text box control .Add the below  function body :

if(document.getElementById("<%=txtWebURL.ClientID %>").value=="")
    {
               alert("Web URL can not be blank");
               document.getElementById("<%=txtWebURL.ClientID %>").value="http://"
               document.getElementById("<%=txtWebURL.ClientID %>").focus();
               return false;
    }
    var Url="^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"
    var tempURL=document.getElementById("<%=txtWebURL.ClientID%>").value;
    var matchURL=tempURL.match(Url);
     if(matchURL==null)
     {
               alert("Web URL does not look valid");
               document.getElementById("<%=txtWebURL.ClientID %>").focus();
               return false;
     }
Where txtWebURL = id of Text Box.

4.       ZIP Format :

This kind of validation used to accept only ZIP format of data in the Text Box control in asp.net. add the below function body :

if (document.getElementById("<%=txtZIP.ClientID%>").value=="")
     {
               alert("Zip Code is not valid");
               document.getElementById("<%=txtZIP.ClientID%>").focus();
               return false;
     }
     var digits="0123456789";
     var temp;
     for (var i=0;i<document.getElementById("<%=txtZIP.ClientID %>").value.length;i++)
     {
               temp=document.getElementById("<%=txtZIP.ClientID%>").value.substring(i,i+1);
               if (digits.indexOf(temp)==-1)
               {
                        alert("Please enter correct zip code");
                        document.getElementById("<%=txtZIP.ClientID%>").focus();
                        return false;
               }
     }

Where txtZIP = id of text box.

When you done with all call the function validate on the Button on which you want output like below :

<asp:Button ID="btnSubmit" OnClientClick=" return validate()" runat="server" Text="Submit" />


Now save the whole work and view the page in browser it ll work perfect.



Thanks


Monday 20 May 2013

ASP.Net: Text Box validation | Neha Sharma




Introduction:

In this article I explain to create validations for Text Box control in ASP.Net. Here I am going to start with three validations:

1.       Accept alphanumeric characters
2.       Accept Alphabet characters
3.       Accept numeric characters

Requirment :

Add the below  line in head section:

 <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>

Code:

 For the point first write the below script in your page :

1.       Accept alphanumeric characters :
<script type="text/javascript">
    $(function () {
        $('#txtalphaNumeric').keydown(function (e) {
            if (e.shiftKey || e.ctrlKey || e.altKey) {
                e.preventDefault();
            } else {
                var key = e.keyCode;
                if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
                    e.preventDefault();
                }
            }
        });
    });

When you have done with this code, add a textbox and mention the id of textbox to  “txtalphaNumeric” like :

<asp:TextBox ID="txtalphaNumeric" runat="server"></asp:TextBox>

2.       Accept Alphabet characters

For the point first write the below script in your page :

$(function () {
        $('#txtalphabet').keydown(function (e) {
            if (e.shiftKey || e.ctrlKey || e.altKey) {
                e.preventDefault();
            } else {
                var key = e.keyCode;
                if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90))) {
                    e.preventDefault();
                }
            }
        });
    });

 When you have done with this code, add a textbox and mention the id of textbox to  “txtalphabet” like :

<asp:TextBox ID="txtalphabet" runat="server"></asp:TextBox>

3.       Accept numeric characters :

For the point first write the below script in your page :

$(function () {
        $('#txtNumeric').keydown(function (e) {
            if (e.shiftKey || e.ctrlKey || e.altKey) {
                e.preventDefault();
            } else {
                var key = e.keyCode;
                if (!((key == 8) || (key == 46) || (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
                    e.preventDefault();
                }
            }
        });
    });

 When you have done with this code, add a textbox and mention the id of textbox to  “txtalphabet” like :

<asp:TextBox ID="txtNumeric" runat="server"></asp:TextBox>

 Complete  code :

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Allow only alphanumeric characters in textbox</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(function () {
        $('#txtalphaNumeric').keydown(function (e) {
            if (e.shiftKey || e.ctrlKey || e.altKey) {
                e.preventDefault();
            } else {
                var key = e.keyCode;
                if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
                    e.preventDefault();
                }
            }
        });
    });

    //only alphabet
    $(function () {
        $('#txtalphabet').keydown(function (e) {
            if (e.shiftKey || e.ctrlKey || e.altKey) {
                e.preventDefault();
            } else {
                var key = e.keyCode;
                if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90))) {
                    e.preventDefault();
                }
            }
        });
    });

    //Only Numeric
    $(function () {
        $('#txtNumeric').keydown(function (e) {
            if (e.shiftKey || e.ctrlKey || e.altKey) {
                e.preventDefault();
            } else {
                var key = e.keyCode;
                if (!((key == 8) || (key == 46) || (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
                    e.preventDefault();
                }
            }
        });
    });
</script>


</head>
<body>
    <form id="form1" runat="server">
<div>
<b>Enter Text:</b><asp:TextBox ID="txtalphaNumeric" runat="server"></asp:TextBox>Accept alphanumeric characters<b><br />
    Enter Text:</b><asp:TextBox ID="txtalphabet" runat="server"></asp:TextBox>
    Accept only Alphabets characters
    Enter text :<asp:TextBox ID="txtNumeric" runat="server"></asp:TextBox>Accept only Numeric values

</div>
        </form>
</body>
</html>

Save all and view the page in browser it ll work fine .



Thanks

Which Game Engine you should choose | Neha Sharma

Unity3D and Unreal Engine are only 2 Game engine which executes an indispensable position in Game Industry. The choice of the engine must ...