Saturday, 28 May 2016

calling web service without adding web reference


Introduction:

Here I will explain how to calling web service without adding web reference using C# code using. Sometimes required to call particular web service without adding web reference at that time we need to call that web service using WebRequest. Once we created and deployed web service that time client required to call webservice so how to do this.

So, Now I explaining how to call web service without adding web reference.


Description: 

In previously post I explained to  
file type validation in jquery
Change the column name or datatype or size in sql server
How to set or get textbox value using Javascript or Jquery
Server does not support secure connections  
Three tier architecture in asp.net
Remove .aspx from url in asp.net

And now here I explain to how to call web service without adding web reference using C# code.

Now copy the following code in your page.

this is the method in MyWebService.asmx wants to call without adding web reference
 


    [WebMethod]
    public string MyDemoWebService(string data1, string data2)
    {
       // Your code here

       return "";

    }


 Now copy the following code in code behind where you want to call web service.

private string CallWebService(string data1, string data2)
    {
        if (Request.IsLocal)
        {

        }
        string result = "";
        string strPost = "data1=" + data1+ "&data2=" + data2;
        StreamWriter myWriter = null;
        HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
        objRequest.Method = "POST";
        objRequest.Timeout = 200000; // this should be greater than IIS / web server's timeout
        objRequest.ContentLength = strPost.Length;
        objRequest.ContentType = "application/x-www-form-urlencoded";
        objRequest.KeepAlive = false;
        try
        {
            myWriter = new StreamWriter(objRequest.GetRequestStream());
            myWriter.Write(strPost);

        }
        catch (Exception e)
        {
            throw new Exception(e.ToString());
        }
        finally
        {
            myWriter.Close();
        }
        HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
        using (StreamReader sr = new StreamReader(objResponse.GetResponseStream)))
        {
            result = sr.ReadToEnd();
            sr.Close();
        }
        return result;
    }
 


  Now call above function CallWebService in your button click event with given parameter and your web service is called without adding web reference. you will get response in result string variavle.

Now run your project and check.

 

 

Friday, 22 April 2016

file size validation in jquery


Introduction:

Here I will explain how to validate file size using Jquery or Javascript. Sometimes required  validation like File size cannot be more than 2Mb or 5MB otherwise alert to user "File size cannot be more than 2Mb or 5MB"

Description: 

In previously post I explained to  
file type validation in jquery
Change the column name or datatype or size in sql server
How to set or get textbox value using Javascript or Jquery
Server does not support secure connections  
textbox allow only characters javascript
button click event not firing in asp.net c#

And now here I explain to how to validate file size using Jquery or Javascript in asp.net.

Now copy the following javascript code in your page.


function IsFileValid() {

        var objFileUpload = document.getElementById("fuContentImage");
        if (objFileUpload.value != null || objFileUpload.value != "") {
        var file;
        file = objFileUpload.files[0];
      

 if (file.size > 2097152) //file.size returns Bytes of the file
        {
                alert("File size cannot be more than 2Mb.");
                return false;
        }
 
    }
}


And copy this html in your page


<h1>how to validate File size cannot be more than 2Mb or 5MB using Jquery or Javascript</h1>

<input type="file" name="Image" id="fuContentImage" />  

<input type="submit" onclick="return IsFileValid();" value="Add" class="btn btn-success" style="width:200px" />

file type validation in jquery


Introduction:

Here I will explain how to validate file type like JPG,PNG or JPEG using Jquery or Javascript. Sometimes required this type of validation like upload only  JPG,PNG or JPEG file otherwise alert to user "file type is not valid to upload "

Description: 

In previously post I explained to  
Change the column name or datatype or size in sql server
How to set or get textbox value using Javascript or Jquery
Server does not support secure connections  
textbox allow only characters javascript
button click event not firing in asp.net c#

And now here I explain to how to validate file type like JPG,PNG or JPEG using Jquery or Javascript in asp.net.

Now copy the following javascript code in your page.



function IsFileValid() {

        var objFileUpload = document.getElementById("fuContentImage");
        if (objFileUpload.value != null || objFileUpload.value != "") {
            var file;
            file = objFileUpload.files[0];
            if ((file.name.split('.').pop().toLowerCase()) == "png" || (file.name.split('.').pop().toLowerCase()) == "jpg" || (file.name.split('.').pop().toLowerCase()) == "jpeg" || (file.name.split('.').pop().toLowerCase()) == "bmp") {

            }
            else {
                alert("Please upload png,jpg or jpeg image only.");
                return false;
            }
           
           
        }
        return true;
    }


And copy this html in your page




<h1>how to validate file type like JPG,PNG or JPEG using Jquery or Javascript</h1>

<input type="file" name="Image" id="fuContentImage" />  

<input type="submit" onclick="return IsFileValid();" value="Add" class="btn btn-success" style="width:200px" />






 


Tuesday, 5 April 2016

Change the column name or datatype or size in sql server

How to change the column name of the table or datatype of the column or size in sql server


1)
How to change column name of the table in SQL

ALTER TABLE TABLENAME
             ALTER COLUMN [NEWCOLUMNNAME] varchar(200)


Example
ALTER TABLE tblUser
             ALTER COLUMN [Name] varchar(200)


2)
How to change datatype of the column in SQL

ALTER TABLE tblUser
             ALTER COLUMN [UserName] varchar(500)


3)
How to change size of the column in SQL

ALTER TABLE tblUser
             ALTER COLUMN [UserName] varchar(500)

How to set or get textbox value using Javascript or Jquery ?

Introduction:

Here I will explain How to set textbox value using Jquery, How to get textbox value using Jquery, How to set textbox value using Javascript, How to get textbox value using Javascript. If you want to How to set or get textbox value using Javascript or Jquery then copy following code in your page.

Description: 

In previously post I explained to  
file type validation in jquery
Change the column name or datatype or size in sql server
How to set or get textbox value using Javascript or Jquery
Server does not support secure connections  
textbox allow only characters javascript
button click event not firing in asp.net c#

And now here I explain to How to set textbox value using Jquery, How to get textbox value using Jquery, How to set textbox value using Javascript, How to get textbox value using Javascript in asp.net.

Now copy the one by one following javascript code in your page.


How to set or get textbox value using Javascript or Jquery ?

How to set textbox value using Javascript


function setValueJavascript() {
        document.getElementById('txtName').value = "Set Value To textbox using javascript";
    }

How to get textbox value using Javascript

function getValueJavascript() {
        var Name = document.getElementById('txtName').value;
        alert(Name);
    }

How to set textbox value using Jquery

function setValueJquery() {
        $("#txtName").val('Set Value To textbox using Jquery');
    }

How to get textbox value using Jquery

function getValueJquery() {
        var Name = $("#txtName").val();
        alert(Name);
    }

Here full example of How to set textbox value using Javascript, How to get textbox value using Javascript How to set textbox value using Jquery and How to get textbox value using Jquery

Example:


<!DOCTYPE html>
<html>
<head>
    <title>How to set or get textbox value using Javascript or Jquery</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js">
    </script>
    
    <script>

    function setValueJavascript() {
        document.getElementById('txtName').value = "Set Value To textbox using javascript";
    }

    function getValueJavascript() {
        var Name = document.getElementById('txtName').value;
        alert(Name);
    }

    function setValueJquery() {
        $("#txtName").val('Set Value To textbox using Jquery');
    }

    function getValueJquery() {
        var Name = $("#txtName").val();
        alert(Name);
    }
    </script>
</head>
<body>
    <h1>How to set or get textbox value using Javascript or Jquery</h1>

    Enter Name: <input type="text" id="txtName" />

    <br /><br />
    <input type="button" value="Set Value Javascript" onclick="setValueJavascript()" />
    <input type="button" value="Get Value Javascript" onclick="getValueJavascript()" />
    <input type="button" value="Set Value Jquery" onclick="setValueJquery()" />
    <input type="button" value="Get Value Jquery" onclick="getValueJquery()" />
</body>
</html>

How to get Value of All textbox of particalar Div

Some times required to get Value of All textbox of particalar Div and inserting or doing some operation to these texboxes value. so I have added this complete code to get Value of All textbox of particalar Div or get Value of multiple textbox of particalar Div using Jquery.

Example:


<!DOCTYPE html>
<html>
<head>
    <title>How to get Value of All textbox of particalar Div</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js">
    </script>

    <script>
        function GetValue() {
            var Contain = "";
            $("#divRegsiter :text").each(function () {
                alert($(this).val());
            });
        }
    </script>
</head>
<body>
    <h1>How to get Value of All textbox of Div</h1>

    <div id="divRegsiter">
        Enter Name: <input type="text" id="txtName" /><br />
        Enter User Name: <input type="text" id="txtUserName" /><br />
        Enter Email: <input type="text" id="txtEmail" /><br />
    </div>
    <div id="divLogin">
        <p>Not getting this textbox value when you click on button, because 
        this is exist in different Div</p>

        Enter Name: <input type="text" id="txtNameLogin" /><br />
    </div>
    <br /><br />
    <input type="button" value="Get All Textboxes Value" onclick="GetValue()" />
</body>
</html>

Server does not support secure connections

Server does not support secure connections

Sometimes this error will getting when try to send mail in asp.net with c# - Server does not support secure connections.

Solution:

  SmtpServer.Port = 587;
  SmtpServer.Timeout = 10000;


Tuesday, 30 June 2015

textbox allow only characters javascript

textbox allow only characters javascript

button click event not firing in asp.net c#

button click event not firing in asp.net c#

This is type of issue many times occurs in asp.net. whenever button click is not execute first check your html
Is <form>   tag in page ?

Form tag must be 1 time only, otherwise your c# event is not execute.




Asp.net tutorials