Archive for May 2013

WCF Function and Database Record Updation

WCF Function  in  ".aspx"  File:


<body>
    <form id="form1" runat="server">


************************************************************************

    <asp:ScriptManager ScriptMode="Release" LoadScriptsBeforeUI="false" ID="sct" runat="server">
        <Services>
            <asp:ServiceReference Path="~/wcfServices/Service1.svc" />
        </Services>
    </asp:ScriptManager>

****************************************************************

  <script language="javascript" type="text/javascript">
    
    function changestatus(val)
    {
  
   Service1.change_status(val, OnSuccess, OnFailed, "");
   return false;
    }
     function OnSuccess(res) {
        if (res != "") {

            
        }
        else {
        }
    }
    function OnFailed(res) {
    }

    
    </script>


**************************************************************
WCF File:
 service1:

<ServiceContract(Namespace:="")> _
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
Public Class Service1

    ' Add <WebGet()> attribute to use HTTP GET 
    <OperationContract()> _
    Public Sub DoWork()
        ' Add your operation implementation here
    End Sub



    <OperationContract()> _
   Public Function change_status(ByVal mid As String) As String
        Dim approveqry As String

        approveqry = "Update mailbox set status=0 where mailid=" & mid

        DBManager.ExecuteNonQuery(approveqry)
        Return "read"

    End Function



**********************************************************



Call The Function:

server side:


  Mail &= " <h3 onclick=" & "'return changestatus(" & dts.Rows(i)("mailid") & ")'" & ">" & dts.Rows(i)("subject") & "  <table align='right'><tr><td align='right'> " & dts.Rows(i)("activity") & "</td> </tr></table></h3>"
                Mail &= "<div><p>" & dts.Rows(i)("mailcontent") & " </p></div>"




Saturday, May 25, 2013
Posted by ஆனந்த் சதாசிவம்
Tag :

Dynamic Upload Button

Javascript:



 function fnAddoption()
 {
            var Cnt = parseInt(document.getElementById("<%=hiddencount1.ClientID %>").value);
            var Cid = parseInt(document.getElementById("<%=hidrowid.ClientID %>").value);
            browser = window.navigator.appName;
            var newtr;
            if (browser == "Microsoft Internet Explorer")
                newtr = document.getElementById('Addimg').insertRow();
            else
                newtr = document.getElementById('Addimg').insertRow(Cid + 1);
            var newtd1 = newtr.insertCell(0);
            var newtd2 = newtr.insertCell(1);
            var newtd4 = newtr.insertCell(2);
            var newtd3 = newtr.insertCell(3);
            newtd1.innerHTML = "";
            newtd2.innerHTML += "<td align='right' width='219'><input class='formTxtBox' style='width:210px; height:20px;'  type='file'  id='txtGalleryFile" + (Cid) + "' name ='txtGalleryFile" + (Cid) + "'  class='txt_box_n' contenteditable='false' value='' onKeyDown='return false;'  onKeyPress='return false;'  ></td>";
            newtd2.height = "";

            //newtd2.innerHTML +="<td align='right'>"
            newtd4.innerHTML += "<td align='right' width='219'><input type='button' name='btnDel' value=' -'  style='height:20px;' onClick=fndel1(this.parentNode.parentNode.rowIndex) >";
            newtd4.innerHTML += "<input type='hidden' name='hidImage" + (Cid) + "' id='hidImage" + (Cid) + "' value=''>";
            newtd3.innerHTML += "";
            document.getElementById("<%=hiddencount1.ClientID %>").value = parseInt(document.getElementById("<%=hiddencount1.ClientID %>").value) + 1;
            document.getElementById("<%=hidrowid.ClientID %>").value = parseInt(document.getElementById("<%=hidrowid.ClientID %>").value) + 1;
            return true;


        }



        function fndel1(no, delid)
 {
            if (delid != undefined) {
                document.getElementById('hiddeletIds').value += delid + ",";
            }
            document.getElementById('Addimg').deleteRow(no);
            document.getElementById("<%=hiddencount1.ClientID %>").value = parseInt(document.getElementById("<%=hiddencount1.ClientID %>").value) - 1;
            document.getElementById("<%=hidrowid.ClientID %>").value = parseInt(document.getElementById("<%=hidrowid.ClientID %>").value) - 1;
        }



Using Page:


 <td>
                                            <table cellpadding="0" cellspacing="0" id="Addimg" height="25px" width="200px">
                                                <tr id="trfirst" runat="server">
                                                    <td align="center">
                                                        <asp:FileUpload ID="imageFileUP" runat="server" Width="219px" />
                                                        <td>
                                                            <input type="button" id="btnincress" onclick=" return fnAddoption();" runat="server"
                                                                style="height: 20px; padding-left: 9px; top: 5px; width: 31px;" value="+" name="btnadd" />
                                                        </td>
                                                    </td>
                                                </tr>
                                            </table>
                                            <asp:Label runat="Server" ID="lblgalleyFile" Style="float: left;" Height="18px" Width="82px"></asp:Label>
                                        </td>


C#  Backend Coding
....................................



#region MultipleUploader
        String MultipleUploader()
        {
            HttpFileCollection Files;
            string[] arrCount = null;
            Files = Request.Files;
            arrCount = Files.AllKeys;
            String OldNames = String.Empty;
            String ImageFileNames = String.Empty;
            string filepath = AppDomain.CurrentDomain.BaseDirectory + "Gallery/";
            if (!Directory.Exists(filepath))
            {
                Directory.CreateDirectory(filepath);
            }
            try
            {
                if (System.IO.Path.GetFileName(Files[arrCount[0]].FileName) != "")
                {
                    String tempfile1 = Guid.NewGuid().ToString().Substring(0, 5);
                    Files[arrCount[0]].SaveAs(filepath + tempfile1 + ".jpg");
                    ImageFileNames += tempfile1 + ".jpg" + "^";
                }
                else
                {
                    ImageFileNames += hidrowEditImgFirstRow.Value + "^";
                }


            }
            catch (Exception ex) { }

            for (int i = 1; i < arrCount.Length; i++)
            {
                try
                {
                    String tempname = Guid.NewGuid().ToString().Substring(0, 5);
                    if (System.IO.Path.GetFileName(Files[arrCount[i]].FileName.Replace("^", "")) != "")
                    {
                        Files[arrCount[i]].SaveAs(filepath + tempname + ".jpg");
                        ImageFileNames += tempname + ".jpg" + "^";
                        //DBclass.fnThumbImg(filepath, ImageFileNames, "image");
                    }


                    else
                    {
                        try
                        {
                            ImageFileNames += Request.Form["hidImage" + (i - 1)].ToString() + "^";
                        }
                        catch (Exception ex)
                        {

                        }
                    }
                }
                catch (Exception ex)
                {

                }
            }
            return ImageFileNames.Substring(0, ImageFileNames.Length - 1);

        }
        #endregion




File Name:
..........................


  string Upload = MultipleUploader();

Wednesday, May 22, 2013
Posted by ஆனந்த் சதாசிவம்

Javascript Validation

  <asp:Button ID="btnsav" class="form_submit" runat="server" Text="Save" OnClick="btnsav_Click1" OnClientClick="return validate()" />

Require field validation:
*********************************************************************************
  if (document.getElementById("<%=txtFirstname.ClientID %>").value == "") {
            alert("Please enter the first name");
            document.getElementById("<%=txtFirstname.ClientID %>").focus()
            return false;
        }
*******************************************************************************
compare Validation:

if (document.getElementById("<%= hdnOldPassword.ClientID %>").value != "0") {
            if (document.getElementById("<%=txtNewPassword.ClientID %>").value != document.getElementById("<%=txtRetypePassword.ClientID %>").value) {
                alert("Re-enter password does not match")
                document.getElementById("<%=txtNewPassword.ClientID %>").focus()
                return false;
            }
        }

******************************************************************************
Email Validation:

  if (document.getElementById("<%=txtEmail.ClientID %>").value=="")
         {
            alert("Please enter the email");
            document.getElementById("<%=txtEmail.ClientID %>").focus()
            return false;
        }

            var exp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
            if (!exp.test(document.getElementById("<%=txtEmail.ClientID %>").value)) {
                alert("Please enter valid Email");
                document.getElementById("<%=txtEmail.ClientID %>").value = "";
                document.getElementById("<%=txtEmail.ClientID %>").focus();
                return false;
            }
   
*****************************************************************************
Drop down Validation:

  if (document.getElementById("<%=ddlMonth.ClientID %>").value == "0") {
            alert("Please select the month");
            document.getElementById("<%=ddlMonth.ClientID %>").focus()
            return false;
        }

******************************************************************************


Zip Code Validation:


   if (Trim(document.getElementById("<%=txtZip.ClientID%>").value) != "") {

       //     alert("");

            var numberFormat = /^\d{0,15}$/;
            if (document.getElementById("<%=txtZip.ClientID%>") != null) {
                if (document.getElementById("<%=txtZip.ClientID%>").value != '') {
                    if (!numberFormat.test(document.getElementById("<%=txtZip.ClientID%>").value)) {
                        alert('Number Only Allowed.');
                        document.getElementById("<%=txtZip.ClientID%>").value = '';
                        document.getElementById("<%=txtZip.ClientID%>").focus();
                        return false;

                    }
                }
            }
            var zip = document.getElementById("<%=txtZip.ClientID %>").value;

            if (zip.length < "5") {
                alert("Zip Code should not be below 5 number");
                return false;

            }


        }
*********************************************************************************

Phone Number Validation:


  if (Trim(document.getElementById("<%=txtPhone.ClientID%>").value) != "") {

            var objRegExp = /^[1-9]\d{2}-\d{3}-\d{4}$/;
            if (objRegExp.test(document.getElementById("<%=txtPhone.ClientID %>").value)) {
            }
            else {
                alert("Please enter the valid phone No.");
                document.getElementById("<%=txtPhone.ClientID %>").focus()
                return false;
            }
        }
*********************************************************************************
Check Box Validation:


 if (document.getElementById("chkTerms").checked == false) {
            alert("Please accept the Terms and Conditions");
            document.getElementById("chkTerms").focus()
            return false;
        }

********************************************************************************

Posted by ஆனந்த் சதாசிவம்

Popular Post

Blogger templates

Labels

Search Box

Follow us on Facebook

- Copyright © .net -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -