Thursday, 14 March 2013

Wampserver, localhost doesn’t work “blank page” , how to fix it

 Wampserver, localhost doesn’t work “blank page” , how to fix it







After installed your wampserver , you have faced some problems or errors like :
-localhost is not working
-localhost shows blank page.
-The port 80 is actually used by another program…
-The service has not been started.




and those errors because of your wampserver is using port 80,so if have any program is also using port 80, then your wamp will fail and not working. you should close the program now i will show you how to do and how to fix the error ,
follow the pictures below :
1 - Open the command prompt , then type netstat -aon , then search for the port ”80″ from the field of “Local Address” , and remember PID number .
2 – Press CTRL + ALT + DELETE  (at the same time )  to open the Task Manager. Then click “View”  then click “Select Columns…”.
3- Select the box of “PID (Process Identifier)”, then click “Ok” button
4- Search the PID number that you taken in the first time , click on it,  then press “End process”
5- Click on the Wampserverer icons , then click “Restart All Services”.
6- Click on the “Localhost” to see the page of localhost

Congratulations , you have fixed the error , now page is not empty .

Sunday, 3 March 2013

How to use Ajax control in asp.net


 



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

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ajax Rating Sample</title>
<style type="text/css">
.ratingEmpty
{
background-image: url(ratingStarEmpty.gif);
width:18px;
height:18px;
}
.ratingFilled
{
background-image: url(ratingStarFilled.gif);
width:18px;
height:18px;
}
.ratingSaved
{
 background-image: url(ratingStarSaved.gif);
width:18px;
height:18px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="ScripManager1" runat="server"/>
<div>
<asp:UpdatePanel ID="pnlRating" runat="server">
<ContentTemplate>
<table width="35%">
<tr>
<td width="27%">
<b>Average Rating:</b>
</td>
<td>
<ajax:Rating ID="ratingControl" AutoPostBack="true" OnChanged="RatingControlChanged" runat="server" StarCssClass="ratingEmpty" WaitingStarCssClass="ratingSaved" EmptyStarCssClass="ratingEmpty" FilledStarCssClass="ratingFilled">
</ajax:Rating>
<b> <asp:label ID="lbltxt" runat="server"/> </b>
</td>
</tr>
<tr>
<td colspan="2">

    <img alt="" src="547022_519232098129731_586795943_n.jpg"
        style="width: 463px; height: 208px" /></td>
</tr>
</table>

    <ajax:Rating ID="Rating1" runat="server" AutoPostBack="true" StarCssClass="ratingEmpty" WaitingStarCssClass="ratingSaved" EmptyStarCssClass="ratingEmpty" FilledStarCssClass="ratingFilled">
    </ajax:Rating>
         
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>











































using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            BindRatingControl();
        }
    }
    protected void RatingControlChanged(object sender, AjaxControlToolkit.RatingEventArgs e)
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("insert into RatingDetails(Rate)values(@Rating)",con);
        cmd.Parameters.AddWithValue("@Rating", ratingControl.CurrentRating);
        cmd.ExecuteNonQuery();
        con.Close();
        BindRatingControl();
      
    }
    protected void BindRatingControl()
    {
        int total = 0;

        DataTable dt = new DataTable();
        con.Open();
        SqlCommand cmd = new SqlCommand("Select Rate from RatingDetails", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dt);
        if(dt.Rows.Count>0)
        {
            for(int i=0;i<dt.Rows.Count;i++)
            {
                total += Convert.ToInt32(dt.Rows[i][0].ToString());
            }
            int average = total/(dt.Rows.Count);
            ratingControl.CurrentRating = average;
            lbltxt.Text = dt.Rows.Count+"user(s) have rated this article";
        }
    }
}