Monday 25 December 2017

Adrotator control in asp.net



ADRotator control is used for displaying advertisements in a web page.this control is available in asp.net. each we visit a web page a different image containing ad  will be displayed. when we click at the image a website will be opened


first we have to create xml file which will contain the description of ads to be displayed in adrotator control. This xml file will contain <Advertisement> tag as the root tag. there will be one or more<Ad> tag inside root tag. each <Ad> tag will contain the information about a advertisement.

first we have to create a project in asp.net



 
now click project menu. select add new item from the project menu.
short cut key:ctrl+|shift+A . in the dialog box select  webform and then click add button
 



now we have to add a xml file in the project. select project>add new item.

in the dialogbox select data from left panel. and select xml file from the right panel.

we can give a name to the xml file as we desire.



details about tags used in xml filre


 


 


Element
Description
<ImageUrl>
contain the path of the image
<NavigateUrl>
url of the web page to be opened when the image is clicked
<AlternateText>
optional contain the text to be displayed when the image can not be displayed
<Keyword>
OPTIONAL. contain the advertisement category
<Impressions>
Optional.   proportions of image. when there is more impression higher is the chances of particular ad can be displayed 


first create a  folder in project and name it as imagaes. then add one or more images in that folder.now the content of xml filer maybe as below:


<?xml version="1.0" encoding="utf-8" ?>


<Advertisements>


  <Ad>


    <ImageUrl>~/images/google.png</ImageUrl>


    <NavigateUrl>http://google.com</NavigateUrl>


    <AlternateText>google</AlternateText>


    <Keyword>google</Keyword>


    <Impressions>50</Impressions>


  </Ad>


  <Ad>


    <ImageUrl>~/images/youtube.png</ImageUrl>


    <NavigateUrl>http://youtube.com</NavigateUrl>


    <AlternateText>youtube</AlternateText>


    <Keyword>youtube</Keyword>


    <Impressions>25</Impressions>


  </Ad>


</Advertisements>


 
now add a adrotator control in project . select f4 property. select ad.xml for advertisemewntfile property of adrotator control. if we give ' _blank' to target property the advertisement site will be displayed in a new window.


 


 


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication18.WebForm1" %>


 


<!DOCTYPE html>


 


<html xmlns="http://www.w3.org/1999/xhtml">


<head runat="server">


    <title></title>


</head>


<body>


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


    <div>


        <asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/ad.xml" Target ="_blank"/>


    </div>


    </form>


</body>


</html>

output:






 

now when we click the image a webpage will be opened as described in NavigateUrl tag in xml file.


 


 





Thank you
Muthu karthikeyan,Madurai.
 

Monday 9 October 2017

Asp.net lesson-6

ASP.NET LESSON-6


CREATE A WEBPAGE AS BELOW.

Sample web form.










<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
  <b>  user Name:</b>
        <asp:TextBox ID="username" runat="server">

        </asp:TextBox>
        <p>
            <b>comments: </b>
            <asp:TextBox TextMode ="MultiLine" Rows ="5" Columns ="25" ID="comments" runat ="server"></asp:TextBox>
        </p>
        <p>
            <asp:Button ID="submit"  Text ="submit" runat ="server" OnClick="submit_Click" />
        </p>
        <p>
            <asp:Label ID="lbloutput" runat ="server"
                ></asp:Label>
        </p>
    </div>
    </form>
</body>
</html>
Program Explanation:
In the above program we just simply added a text box, a multiline textbox, a button and a output label.
The second text box become a multiline text box because we have assigned the attribute textmode=”Multiline”..
We have to give our name and comments in the output screen and we will have to click button
  protected void submit_Click(object sender, EventArgs e)
    {
        lbloutput.Text = "Thank you" + username.Text + "for the following comments<br>" +"<tt>"+ comments.Text+"</tt>";

    }
}
To add submit_Click() method follow the rules.

1.  Select button and press f4
2.  Property box window will display.
3.  In the below as indicated select lightning icon.
4.  put the cursor at the property box In the click event and double click
5.  now a new window opens and type the code in submit_Click method.






Output: