vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Monday, February 25, 2013

How to call server side method code using javascript in asp.net




Here I would like to share code and process to call server side from the javascript. But in many cases we need to call any event method from javascript,In such cases I hope this article would help to resolve your process.
Initially you can call server side method event by two method of code. Here I illustrate with proper example to when we need to call method event using javascript.
Scenario 1;
Take as scenario in textbox when user enter text after the completion when users press enter key, you need to call the method in server side.

<asp:TextBox ID="TextBox1"  runat="server" onkeypress="return EnterEvent(event)"></asp:TextBox>   
<asp:Button ID="Button3" runat="server" style="display:none" Text="Button" />

In javascript we need to write a function enter event to call server side code button event.
<script type="text/javascript">
function EnterEvent(e) {
        if (e.keyCode == 13) {
            __doPostBack('<%=Button3.ClientID%>', "");
        }
    }
</script>

So when user press enter key it will call the button3 server side code event.

Scenario 2:

Also we can call server side code by another using this anther way i.e.
function caller(){
        document.getElementById('<%= Button3.ClientID %>').click(); 
        }

By using above code have alternate way to call server side from javascript.
I hope this article would helpful to you post your comments
Share this article with your friends by using share button.


Sunday, February 10, 2013

How to use LINQ query in XML data souce



Here I share the usage of LINQ in xml.Normally xml has been to store the data like a database. By using LINQ query we can easily search or retrieve the data from XML.
In a previous article I explained, How LINQ query used in List Collection. For your reference I have mention URL as below.


Now here I explain how to use LINQ query on XML
Take xml file like as structure as below………

Stud.xml

<students>
<student Group="A">
<name>raju</name>
<class>10th</class>
</student>
<student Group="A">
<name>raju</name>
<class>10th</class>
</student>
<student Group="B">
<name>raju</name>
<class>5th</class>
</student>
<student Group="C">
<name>rahman</name>
<class>5th</class>
</student>
<student Group="A">
<name>sekhar</name>
<class>7th</class>
</student>
<student Group="B">
<name>rahuk</name>
<class>8th</class>
</student>
</s</students>

First we need to add namespace to use XML class in LINQ.
using System.Xml.Linq;
then we need to use XDOCUMENT class to load XML file to apply LINQ query.
In First query I am going to search the name contains “Raju” bu using LINQ query


XDocument xd=XDocument.Load(Server .MapPath ("stud.xml"));
        var xmldata = from xm in xd.Descendants("student") where xm.Element ("name").Value .Equals ("raju")
                      select new
                      {
                          name = xm.Element("name").Value,
                          studclass = xm.Element("class").Value
                      };
        foreach (var post in xmldata)
        {
            Response.Write(post.name);
            Response.Write(post.studclass);
        }

Output:
1raju10th
raju10th
raju5th

In a second process now we can filter by group…
var xmldata1 = from xm1 in xd.Descendants("student")
                       where xm1.Attribute("Group").Value.Equals("A")
                       select new
                       {
                           name = xm1.Element("name").Value,
                           studclass = xm1.Element("class").Value
                       };

        foreach (var post1 in xmldata1)
        {
            Response.Write(post1.name);
            Response.Write(post1.studclass + "</br>" );
        }

Output:
raju10th
raju10th
sekhar7th

I hope now you have got an idea to LINQ in xml

How to redirect the user automatically to Http to Https




Here I would like to share to redirect http to https when user enter http URL.
To know more about SSL working method you refer the below links...
Its common one when user can enter URL start with http on web browser. But as a developer, we must find and redirect the user to secure layer. By achieve the process number of method are following like write code on page load or in begin request. Here I have mentioned code would support for all dot net framework.

You need to add the below code on web config file.by doing so when user enter http url it will redirect t to https .
Also make sure you must check use SSL secure setting in IIS then add rule code on web.config file 

 <rule name="http to https" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:0}" />
                </rule>


Please share the article with your friend by using sharing button…..