PDA

View Full Version : سوال: استفاده از Ajax برای تگهای HTML



forodo
چهارشنبه 16 مهر 1393, 15:33 عصر
سلام
من چطوری می تونم مثلاً برای تگ a یدونه Ajax بنوسیم؟
الان 2روزه دارم می خورم اینترنتو ولی هیچی به هیچی.
مثلاً می خوام برای این از ajax استفاده کنم:

Response.Write("<a href=\"Main.aspx?Page=" + i + "&Type=" + Request.QueryString["Type"] + "\"><li>" + i + "</li></a>");
تو عکس پایین می خوام وقتی که روی یکی از اعداد که به روش بالا ایجاد شده کلیک کردم فقط قسمت قرمز رنگ تغییر کنه و رفرش انجام نشه.
http://8pic.ir/images/fbgnszaci1opo1idelcn.png

این کدهای اون ناحیه قرمز رنگ هستش:


<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<%
try
{
using (System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection(ConfigurationM anager.ConnectionStrings["MyCon"].ConnectionString))
{
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter();
System.Data.DataTable dt = new System.Data.DataTable();
da.SelectCommand = new System.Data.SqlClient.SqlCommand();
if (Request.QueryString["Type"] != null)
{
da.SelectCommand.CommandText = "SELECT *,dbo.fn_Counter(ID) AS CountComment FROM tblTraining WHERE tblTypeOfTrainingID = " + Convert.ToInt32(Request.QueryString["Type"]) + " ORDER BY SendDate DESC, SendTime DESC";
}
else
{
da.SelectCommand.CommandText = "SELECT *,dbo.fn_Counter(ID) AS CountComment FROM tblTraining ORDER BY SendDate DESC, SendTime DESC";
}
da.SelectCommand.Connection = sqlConn;
sqlConn.Open();
da.Fill(dt);
sqlConn.Close();
int dtCount = dt.Rows.Count;
try
{
if (Request.QueryString["Page"] != null)
{
for (int i = (3 * (Convert.ToInt32(Request.QueryString["Page"]))) - 3; i < 3 * (Convert.ToInt32(Request.QueryString["Page"])); i++)
{
Response.Write("<div id=\"Content\"><div><div class=\"Mozu\">" + dt.Rows[i]["Subject"] + "</div><div><ul class=\"MozuInformation\"><li style=\"padding-right:0px;\">تاریخ ایجاد : " + dt.Rows[i]["SendDate"] + "</li><li>بازدید : " + dt.Rows[i]["Visit"] + "</li><li>نظرات : " + dt.Rows[i]["CountComment"] + "</li></ul></div><div class=\"MatneAamuzesh\">" + dt.Rows[i]["SummaryOfTraining"] + "</div><div class=\"EdameyeMatlab\"><a href=\"Show.aspx?IdShow=" + dt.Rows[i]["ID"] + "\">... ادامه مطلب</a></div></div></div>");
Response.Write("<div style=\"background-color:#DDD; height:10px; clear:left;\"><!--خالی--></div>");
}
}
else
{
for (int i = 0; i < 3; i++)
{
Response.Write("<div id=\"Content\"><div><div class=\"Mozu\">" + dt.Rows[i]["Subject"] + "</div><div><ul class=\"MozuInformation\"><li style=\"padding-right:0px;\">تاریخ ایجاد : " + dt.Rows[i]["SendDate"] + "</li><li>بازدید : " + dt.Rows[i]["Visit"] + "</li><li>نظرات : " + dt.Rows[i]["CountComment"] + "</li></ul></div><div class=\"MatneAamuzesh\">" + dt.Rows[i]["SummaryOfTraining"] + "</div><div class=\"EdameyeMatlab\"><a href=\"Show.aspx?IdShow=" + dt.Rows[i]["ID"] + "\">... ادامه مطلب</a></div></div></div>");
Response.Write("<div style=\"background-color:#DDD; height:10px; clear:left;\"><!--خالی--></div>");
}
}
}
catch (Exception)
{

}
}
}
catch
{
Response.Write("Error: Error while downloading file!");
}

%>

</div>
<div style="background-color:#DDD; height:10px; clear:left;">
<!--خالی-->
</div>
<div class="PageNumber">
<ul>
<%

using (System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection(ConfigurationM anager.ConnectionStrings["MyCon"].ConnectionString))
{
using (System.Data.SqlClient.SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand())
{
if (Request.QueryString["Type"] != null)
{
sqlCmd.CommandText = "SELECT * FROM tblTraining WHERE tblTypeOfTrainingID = " + Convert.ToInt32(Request.QueryString["Type"]);
}
else
{
sqlCmd.CommandText = "SELECT * FROM tblTraining";
}
sqlCmd.Connection = sqlConn;
sqlConn.Open();
System.Data.SqlClient.SqlDataReader dr = sqlCmd.ExecuteReader();
int counter = 0;
if (dr.HasRows)
{
while (dr.Read())
{
counter++;
}
}
int counterPage = 0;
if (counter % 3 == 0)
{
counterPage = counter / 3;
}
else
{
counterPage = (counter / 3) + 1;
}
Response.Write("<li style=\"float:right; margin:-8px 10px 0px 0px;\">صفحه 1 از " + counterPage + "</li>");
for (int i = counterPage; i >= 2; i--)
{
if (i == Convert.ToInt32(Request.QueryString["Page"]))
{
if (Request.QueryString["Type"] != null)
{
Response.Write("<a href=\"Main.aspx?Page=" + i + "&Type=" + Request.QueryString["Type"] + "\"><li style=\"background-color:#069;\">" + i + "</li></a>");
}
else
{
Response.Write("<a href=\"Main.aspx?Page=" + i + "\"><li style=\"background-color:#069;\">" + i + "</li></a>");
}

}
else
{
if (Request.QueryString["Type"] != null)
{
Response.Write("<a href=\"Main.aspx?Page=" + i + "&Type=" + Request.QueryString["Type"] + "\"><li>" + i + "</li></a>");
}
else
{
Response.Write("<a href=\"Main.aspx?Page=" + i + "\"><li>" + i + "</li></a>");
}
}
}
if (1 == Convert.ToInt32(Request.QueryString["Page"]) || Request.QueryString["Page"] == null)
{
if (Request.QueryString["Type"] != null)
{
Response.Write("<a href=\"Main.aspx?Page=1&Type=" + Request.QueryString["Type"] + "\"><li style=\"background-color:#069;\">1</li></a>");
}
else
{
Response.Write("<a href=\"Main.aspx?Page=1\"><li style=\"background-color:#069;\">1</li></a>");
}
}
else
{
if (Request.QueryString["Type"] != null)
{
Response.Write("<a href=\"Main.aspx?Page=1&Type=" + Request.QueryString["Type"] + "\"><li>1</li></a>");
}
else
{
Response.Write("<a href=\"Main.aspx?Page=1\"><li>1</li></a>");
}
}


//Response.Write("<li>. . .</li>");
//Response.Write("<a href=\"Main.aspx?Page=" + counterPage + "\"><li>" + counterPage + "</li></a>");
}
}

%>
<asp:LinkButton runat="server" >LinkButton</asp:LinkButton>
</ul>

</div>
</ContentTemplate>
</asp:UpdatePanel>

</div>