Friday, December 31, 2010
Monday, December 27, 2010
twitter notifications jquery
<!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>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<title>Jquery</title>
<style type="text/css">
#response
{
height: 50px;
background-color: #80E6FF;
position: absolute;
width: 100%;
top: 0px;
left: 0px;
text-align: center;
text-align: center;
font-style: normal;
font-size: x-large;
font-family: "Comic Sans MS";
}
</style>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$('#response').hide();
$('#response').click(function() {
$('#response').slideUp('fast');
});
$('#show').click(function() {
$('#response').slideDown('slow');
$('#response').html('Settings saved successfully!');
});
});
</script>
</head>
<body>
<label id="show">Click to Save settings.</label>
<div id="response"></div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<title>Jquery</title>
<style type="text/css">
#response
{
height: 50px;
background-color: #80E6FF;
position: absolute;
width: 100%;
top: 0px;
left: 0px;
text-align: center;
text-align: center;
font-style: normal;
font-size: x-large;
font-family: "Comic Sans MS";
}
</style>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$('#response').hide();
$('#response').click(function() {
$('#response').slideUp('fast');
});
$('#show').click(function() {
$('#response').slideDown('slow');
$('#response').html('Settings saved successfully!');
});
});
</script>
</head>
<body>
<label id="show">Click to Save settings.</label>
<div id="response"></div>
</body>
</html>
Sunday, December 26, 2010
jquery post sample
Database table:
CREATE TABLE `comments` (
`id` INT( 5 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 50 ) NOT NULL ,
`comment` VARCHAR( 255 ) NOT NULL ,
`time` INT( 9 ) NOT NULL
)
process.php
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "newdb";
$name=$_POST['name'];
$comment=$_POST['comment'];
$conn=mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error);
$select_db=mysql_select_db($dbname) or die("cannot find database!");
$sql= "INSERT INTO comments (`name`,`comment`,`time`) values ('$name','$comment',".time().")";
mysql_query($sql) or die("insert failed.");
echo true;
?>
index.php
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<title>Jquery - samples</title>
<style>
#response
{
border: 5px solid #99CCFF;
background: #00CCFF;
}
</style>
<script type="text/javascript">
$(document).ready(function()
{
$("#response").hide();
$("#addComment").click(function()
{
if( $("#name").val()!='' && $("#comment").val()!='')
{
$.post(
"process.php",
{
name:$("#name").val(),
comment:$("#comment").val()
},
function(response)
{
if(response == true )
{
$("#response").fadeIn('normal');
$("#response").html('Comment Added!');
$("#name").val('');
$("#comment").val('');
}
else
{
$("#response").fadeIn('normal');
$("#response").html('Insertion failed!');
}
}
);
}
else
{
$("#response").fadeIn('normal');
$("#response").html('Please enter your name and comment!');
}
return false;
});
$("#response").click(function()
{
$("#response").fadeOut('slow');
});
$("#resetall").click(function()
{
$("#name").val('');
$("#comment").val('');
$("#response").hide();
});
});
</script>
</head>
<body>
<form id="commentform">
<table width="100%" border="1">
<tr>
<th scope="row">Name</th>
<td><input name="name" type="text" id="name" size="50"/></td>
</tr>
<tr>
<th scope="row">Comment</th>
<td><textarea id="comment" name="Comment" cols="50" rows="3" ></textarea></td>
</tr>
<tr>
<th scope="row"> </th>
<td><input name="submit" type="submit" id="addComment" value="Add"/>
<input name="button" type="button" id="resetall" value="Reset"/></td>
</tr>
</table>
</form>
<div id="response"></div>
</body>
</html>
CREATE TABLE `comments` (
`id` INT( 5 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 50 ) NOT NULL ,
`comment` VARCHAR( 255 ) NOT NULL ,
`time` INT( 9 ) NOT NULL
)
process.php
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "newdb";
$name=$_POST['name'];
$comment=$_POST['comment'];
$conn=mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error);
$select_db=mysql_select_db($dbname) or die("cannot find database!");
$sql= "INSERT INTO comments (`name`,`comment`,`time`) values ('$name','$comment',".time().")";
mysql_query($sql) or die("insert failed.");
echo true;
?>
index.php
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<title>Jquery - samples</title>
<style>
#response
{
border: 5px solid #99CCFF;
background: #00CCFF;
}
</style>
<script type="text/javascript">
$(document).ready(function()
{
$("#response").hide();
$("#addComment").click(function()
{
if( $("#name").val()!='' && $("#comment").val()!='')
{
$.post(
"process.php",
{
name:$("#name").val(),
comment:$("#comment").val()
},
function(response)
{
if(response == true )
{
$("#response").fadeIn('normal');
$("#response").html('Comment Added!');
$("#name").val('');
$("#comment").val('');
}
else
{
$("#response").fadeIn('normal');
$("#response").html('Insertion failed!');
}
}
);
}
else
{
$("#response").fadeIn('normal');
$("#response").html('Please enter your name and comment!');
}
return false;
});
$("#response").click(function()
{
$("#response").fadeOut('slow');
});
$("#resetall").click(function()
{
$("#name").val('');
$("#comment").val('');
$("#response").hide();
});
});
</script>
</head>
<body>
<form id="commentform">
<table width="100%" border="1">
<tr>
<th scope="row">Name</th>
<td><input name="name" type="text" id="name" size="50"/></td>
</tr>
<tr>
<th scope="row">Comment</th>
<td><textarea id="comment" name="Comment" cols="50" rows="3" ></textarea></td>
</tr>
<tr>
<th scope="row"> </th>
<td><input name="submit" type="submit" id="addComment" value="Add"/>
<input name="button" type="button" id="resetall" value="Reset"/></td>
</tr>
</table>
</form>
<div id="response"></div>
</body>
</html>
Tuesday, December 21, 2010
asp.net and sql server
aspx page
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="Load all" />
</form>
</body>
web.config
<appSettings>
<add key="localhost" value="dbConnectionString"/>
</appSettings>
<connectionStrings>
<add name="dbConnectionString" connectionString="Data Source=.\SQLEXPRESS; User ID=sa; Password=pswd; Database=testdatas; TimeOut=1 " providerName="System.Data.SqlClient"/>
</connectionStrings>
aspx page.cs
public partial class _Default : System.Web.UI.Page
{
SqlConnection sqlcon;
SqlCommand SqlCmd;
string ConnectionName = "";
string ConnectionString = "";
SqlDataReader SqlDr;
List<string> LstString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Response.Write(DateTime.Now.ToString());
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ConnectionName = ConfigurationManager.AppSettings["localhost"].ToString();
ConnectionString = ConfigurationManager.ConnectionStrings[ConnectionName].ToString();
sqlcon = new SqlConnection();
SqlCmd = new SqlCommand();
sqlcon.ConnectionString = ConnectionString;
SqlCmd.CommandText = "insert into tbone (name) values (@users)";
SqlCmd.Parameters.AddWithValue("@users",TextBox1.Text);
SqlCmd.Connection = sqlcon;
sqlcon.Open();
SqlCmd.ExecuteNonQuery();
sqlcon.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
ConnectionName = ConfigurationManager.AppSettings["localhost"].ToString();
ConnectionString = ConfigurationManager.ConnectionStrings[ConnectionName].ToString();
sqlcon = new SqlConnection();
SqlCmd = new SqlCommand();
LstString = new List<string>();
sqlcon.ConnectionString = ConnectionString;
SqlCmd.CommandText = "select * from tbone";
SqlCmd.Parameters.AddWithValue("@users", TextBox1.Text);
SqlCmd.Connection = sqlcon;
sqlcon.Open();
SqlDr = SqlCmd.ExecuteReader();
while (SqlDr.Read())
{
LstString.Add(SqlDr["name"].ToString());
}
SqlDr.Close();
sqlcon.Close();
DropDownList1.DataSource = LstString;
DropDownList1.DataBind();
}
}
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="Load all" />
</form>
</body>
web.config
<appSettings>
<add key="localhost" value="dbConnectionString"/>
</appSettings>
<connectionStrings>
<add name="dbConnectionString" connectionString="Data Source=.\SQLEXPRESS; User ID=sa; Password=pswd; Database=testdatas; TimeOut=1 " providerName="System.Data.SqlClient"/>
</connectionStrings>
aspx page.cs
public partial class _Default : System.Web.UI.Page
{
SqlConnection sqlcon;
SqlCommand SqlCmd;
string ConnectionName = "";
string ConnectionString = "";
SqlDataReader SqlDr;
List<string> LstString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Response.Write(DateTime.Now.ToString());
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ConnectionName = ConfigurationManager.AppSettings["localhost"].ToString();
ConnectionString = ConfigurationManager.ConnectionStrings[ConnectionName].ToString();
sqlcon = new SqlConnection();
SqlCmd = new SqlCommand();
sqlcon.ConnectionString = ConnectionString;
SqlCmd.CommandText = "insert into tbone (name) values (@users)";
SqlCmd.Parameters.AddWithValue("@users",TextBox1.Text);
SqlCmd.Connection = sqlcon;
sqlcon.Open();
SqlCmd.ExecuteNonQuery();
sqlcon.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
ConnectionName = ConfigurationManager.AppSettings["localhost"].ToString();
ConnectionString = ConfigurationManager.ConnectionStrings[ConnectionName].ToString();
sqlcon = new SqlConnection();
SqlCmd = new SqlCommand();
LstString = new List<string>();
sqlcon.ConnectionString = ConnectionString;
SqlCmd.CommandText = "select * from tbone";
SqlCmd.Parameters.AddWithValue("@users", TextBox1.Text);
SqlCmd.Connection = sqlcon;
sqlcon.Open();
SqlDr = SqlCmd.ExecuteReader();
while (SqlDr.Read())
{
LstString.Add(SqlDr["name"].ToString());
}
SqlDr.Close();
sqlcon.Close();
DropDownList1.DataSource = LstString;
DropDownList1.DataBind();
}
}
Subscribe to:
Posts (Atom)