Why can't I see ajax slide show images when I run? - asp.net

I'd like to have an ajax slideshow on my web site. I get image urls from a database.
I think the code is right,but when I debug it my database photos are not shown.
I'm sure that my photos load completely.
<ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajax:ToolkitScriptManager>
<div align="center">
<asp:Image ID="imgslides" runat="server" Height="400px"
ImageUrl="Gallery images/72007_205.jpg" BorderColor="Black"
BorderStyle="Solid" BorderWidth="5 px" />
<asp:Button ID="btnPrevious" runat="server" Text="Prev" />
<asp:Button ID="btnPlay" runat="server" Text="Play" />
<asp:Button ID="btnNext" runat="server" Text="Next" />
<ajax:SlideShowExtender ID="SlideShowExtender1"
runat="server" AutoPlay="true" Loop="true"
NextButtonID="btnNext"
PreviousButtonID="btnPrevious"
PlayButtonID="btnPlay"
PlayButtonText="Play"
StopButtonText="Stop"
TargetControlID="imgslides"
SlideShowServiceMethod="GetSlides"
SlideShowServicePath = "Slideshow.asmx">
</ajax:SlideShowExtender>
and this is my web service code Slideshow.asmx
public AjaxControlToolkit.Slide[] GetSlides()
{
SqlConnection myconn = new SqlConnection();
myconn.ConnectionString = "Data Source=PARISA-PC;Initial Catalog=Images;Integrated Security=True";
myconn.Open();
string selectCmd = "select * from images";
string countCmd = "select count(*) from images";
SqlCommand myCmd = new SqlCommand(selectCmd,myconn);
SqlCommand myCmd2 = new SqlCommand(countCmd,myconn);
int i = 0;
SqlDataReader dr = myCmd.ExecuteReader();
ArrayList ar = new ArrayList();
try
{
while (dr.Read())
{
ar.Add(dr.GetString(2));
}
}
catch (Exception)
{
throw;
}
myconn.Close();
AjaxControlToolkit.Slide[] Photos = new AjaxControlToolkit.Slide[ar.Count];
for(i=0 ; i< ar.Count ; i++){
Photos[i] = new AjaxControlToolkit.Slide(ar[i].ToString(),"image"+i.ToString(),"Booth's images");
}
return Photos;
}
[1]: http://i.stack.imgur.com/eMw4S.jpg

You have to use http handler or an aspx page (which showing images from database). Then you can send the Query String to that handler or aspx for a particular image from ajax slide web service. You can get enough examples in google about it.

Related

force a page refresh from code behind inside the ajax file upload control event

I am using Ajax File Upload to insert some images into my database and also i am using a data-list to display those images.
<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" runat="server" Height="141px" Width="640px" MaximumNumberOfFiles="100" OnUploadStart="AjaxFileUpload1_UploadStart" OnUploadComplete="AjaxFileUpload1_UploadComplete" OnUploadCompleteAll="AjaxFileUpload1_UploadCompleteAll" />
and the data-list
<asp:DataList ID="dlImages" runat="server" RepeatColumns="3" CellPadding="5">
<ItemTemplate>
<a id="imageLink" href='<%# Eval("ImageName","~/SlideImages/{0}") %>' title='<%#Eval("Description") %>' rel="prettyPhoto[pp_gal]" runat="server" >
<asp:Image ID="Image1" ImageUrl='<%# Bind("ImageName", "~/SlideImages/{0}") %>' runat="server" Width="112" Height="84" />
</a>
</ItemTemplate>
<ItemStyle BorderColor="Brown" BorderStyle="dotted" BorderWidth="3px" HorizontalAlign="Center"
VerticalAlign="Bottom" />
</asp:DataList>
and the code behind as follows :-
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDataList();
}
}
protected void BindDataList()
{
con.Open();
SqlCommand command = new SqlCommand("SELECT ImageName,Description from SlideShowTable", con);
SqlDataAdapter da = new SqlDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
dlImages.DataSource = dt;
dlImages.DataBind();
con.Close();
}
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string fileName = Path.GetFileName(e.FileName);
string filePath = "~/SlideImages/";
AjaxFileUpload1.SaveAs(MapPath(filePath + System.IO.Path.GetFileName(e.FileName)));
con.Open();
SqlCommand cmd = new SqlCommand("Insert into SlideShowTable(ImageName,Description) values(#ImageName,#Description)", con);
cmd.Parameters.AddWithValue("#ImageName", fileName);
cmd.Parameters.AddWithValue("#Description", "Some Description");
cmd.ExecuteNonQuery();
con.Close();
BindDataList();
}
protected void AjaxFileUpload1_UploadCompleteAll(object sender, AjaxControlToolkit.AjaxFileUploadCompleteAllEventArgs e)
{
Response.Redirect("~/Demo.aspx");
Server.TransferRequest(Request.Url.AbsolutePath, false);
Response.Redirect(Request.Url.AbsoluteUri);
}
Now the Problem is that on using the conventional ASP file upload control post back happens and page refreshes automatically and my data-list binds and after upload the data-list gets updated with new images. But on using the Ajax File Upload there is no post-back and no refresh happens despite the fact i have tried different things
Response.Redirect("~/Demo.aspx");
Server.TransferRequest(Request.Url.AbsolutePath, false);
Response.Redirect(Request.Url.AbsoluteUri);
but still i cant get the page to refresh and i have to manually refresh the page to get the updated Data-list on my page. Any help or solution is appreciated. Thank You.

how to formate string of tree view

i have one tree view. i want to formate appended string like grid view:
<ItemTemplate>
<asp:Label ID="lbut_subject" runat="server"
Text='<%#Eval("Inquiry_subject").ToString().Length > 10 ? Eval("Inquiry_subject").ToString().Substring(0,10)+"..." :Eval("Inquiry_subject") %>'
ToolTip='<%# Bind("Inquiry_subject") %>'></asp:Label>
</ItemTemplate>
how ever i want this this to do with my tree view:
<asp:TreeView ID="TV_Question_Summary" runat="server" ImageSet="Simple" ShowLines="True" OnTreeNodeDataBound="TV_Question_Summary_DataBound" SkipLinkText="">
<DataBindings>
<asp:TreeNodeBinding DataMember="Root" FormatString=" {0}" TextField="" ValueField=""/>
<asp:TreeNodeBinding DataMember="ParentNode" FormatString=" {0}" TextField="Inquiry_id" ValueField="Inquiry_id"/><asp:TreeNodeBinding DataMember="Node" FormatString=" {0}" TextField="body" ValueField="Inquiry_id" ToolTip="body"/>
</DataBindings>
</asp:TreeView>
i want to string presentation like ... if Node filed body string gets overflow of no of 15 chars...
for binding up text i use this code:
void fill_Tree()
{
using (SqlConnection conn = Util.GetConnection())
{
conn.Open();
SqlCommand SqlCmd = new SqlCommand("Select * from tbl_Inquiry_History Where (IsDisplay='True')", conn);
SqlDataReader Sdr = SqlCmd.ExecuteReader();
SqlCmd.Dispose();
string[,] ParentNode = new string[100, 2];
int count = 0;
while (Sdr.Read())
{
ParentNode[count, 0] = Sdr.GetValue(Sdr.GetOrdinal("Inquiry_id")).ToString();
ParentNode[count++, 1] = Sdr.GetValue(Sdr.GetOrdinal("Inquiry_id")).ToString();
}
Sdr.Close();
for (int loop = 0; loop < count; loop++)
{
TreeNode root = new TreeNode();
root.Text = ParentNode[loop, 1];
root.NavigateUrl = "~/Admin/OWM_Inquiry.aspx?inquiryid="+ ParentNode[loop, 1];
SqlCommand Module_SqlCmd = new SqlCommand("Select * from tbl_Question where (Inquiry_id = #parent_id AND IsCount='False')", conn);
Module_SqlCmd.Parameters.AddWithValue("#parent_id", ParentNode[loop, 0]);
SqlDataReader Module_Sdr = Module_SqlCmd.ExecuteReader();
while (Module_Sdr.Read())
{
TreeNode child = new TreeNode();
child.Text = Module_Sdr.GetValue(Module_Sdr.GetOrdinal("body")).ToString();
child.NavigateUrl = "~/Admin/OWM_Inquiry.aspx?inquiryid="+ParentNode[loop, 0];
root.ChildNodes.Add(child);
}
Module_Sdr.Close();
TV_Question_Summary.Nodes.Add(root);
}
TV_Question_Summary.CollapseAll();
}
}
please help me...
Try using a code-behind method instead of embedded code blocks, like this:
protected string DisplayInquirySubject(string inquirySubject)
{
return inquirySubject.Length > 10
? inquirySubject.Substring(0, 10)
: inquirySubject;
}
Now in your markup, you can call the method like this:
<ItemTemplate>
<asp:Label ID="lbut_subject" runat="server"
Text='<%# DisplayInquirySubject(Eval("Inquiry_subject").ToString()) %>'
ToolTip='<%# Bind("Inquiry_subject") %>'>
</asp:Label>
</ItemTemplate>
This has two benefits, it simplifies your markup logic and it allows you to leverage the power of the Visual Studio code editor (i.e. Intellisense and debugging).

SQL Server entry using URL querystring

I am getting a URL from PIC 32 controller using it's post function.
which is like, www.example.com/Default.aspx?x=12&y=23
What I want to do is that when I get the URL, I want to store the values of x and y into SQL Server.
I have launched a .aspx using the IIS server on my system. The coding of the aspx page is..
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Sample Configuration Page</title>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td>IP Address:</td>
<td>
<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>MAC Address:</td>
<td>
<asp:TextBox ID="TxtUserName" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</div>
<asp:Button ID="Button1" runat="server" Text="Save"
onclick="Button1_Click" />
</form>
</body>
</html>
Please guide me with this.
The data will be stored in the database with following C# code,
SqlConnection conn = new SqlConnection(GetConnectionString());
string sql = "INSERT INTO tblRegistration1 (IP, MAC) VALUES "
+ " (#IP_Address,#MAC_Address)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[6];
//param[0] = new SqlParameter("#id", SqlDbType.Int, 20);
param[0] = new SqlParameter("#IP_Address", SqlDbType.VarChar, 50);
param[1] = new SqlParameter("#MAC_Address", SqlDbType.VarChar, 50);
param[0].Value = IP_Address;
param[1].Value = MAC_Address;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
public string GetConnectionString()
{
//sets the connection string from your web config file "ConnString" is the name of your Connection String
return System.Configuration.ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString;
}
Everything is fine while using it with the computer browser.
But the post coming from the PIC32 is not executing. I dont know how do i proceed with the URL coming back to my IIS server which contains IP and MAC details.
In my application I m having these data from PIC32 plat from as well computers.
I hope I have made my self clear.
To get a variable form URL use
Request.QueryString["variable"];
So you can use SqlDataSource to establish SQL Connection or SqlConnection
SqlDataSource
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:Conn %>'InsertCommand="INSERT INTO [TableName] ([x], [y]) VALUES (#x, #y)" >
<InsertParameters>
<asp:QueryStringParameter Name="x" Type="Int16"></asp:Parameter>
<asp:QueryStringParameter Name="y" Type="Int16"></asp:Parameter>
</InsertParameters>
</asp:SqlDataSource>
SqlConnection
public void insertData()
{
using (SqlConnection con = new SqlConnection(conString))
{
con.Open();
try
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO TableName(x, y) VALUES(#x, #y)", con))
{
cmd.Parameters.Add(new SqlParameter("x", Request.QueryString["x"]));
cmd.Parameters.Add(new SqlParameter("y", Request.QueryString["y"]));
cmd.ExecuteNonQuery();
}
}
catch (Exception Ex)
{
Console.WriteLine("Unable To Save Data. Error - " + Ex.Message);
}
}
}

need a code for youtube thumbnail with play button after i click to play the video will play in popup

i need a code for youtube thumbnail with play button which fetch the video id from url after i click to play the video will play in popup... can anyone suggest...?
.aspx code:
<asp:DataList ID="DataList3" runat="server" RepeatDirection="Horizontal"
RepeatColumns="7" Width="600px" DataSourceID="SqlDataSource1">
<ItemTemplate>
Description:
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
<br />
<object width="200" height="200"><param name="movie" value='<%#DataBinder.Eval(Container.DataItem, "url") %>'></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src='<%#DataBinder.Eval(Container.DataItem, "url") %>' type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="200" height="200">
</embed>
</object>
<br />
<br />
</ItemTemplate>
</asp:DataList>
.aspx.cs code
string url = txturl.Text;
if (url.Contains("youtube.com"))
{
string ytFormattedUrl = GetYouTubeID(url);
if (!CheckDuplicate(ytFormattedUrl))
{
SqlCommand cmd = new SqlCommand("INSERT INTO YoutubeVideo VALUES ('" + ytFormattedUrl + "','" + lbluser.Text + "','" + title.Text + "','" + DateTime.Today.Date + "','" + DateTime.Now.TimeOfDay + "')", con);
using (con)
{
con.Open();
int result = cmd.ExecuteNonQuery();
if (result != -1)
{
DataList1.DataBind();
}
else { Response.Write("Error inserting new url!"); }
}
}
else { Response.Write("This video already exists in our database!"); }
}
else
{
Response.Write("This URL is not a valid YOUTUBE video link because it does not contain youtube.com in it");
}
}
private string GetYouTubeID(string youTubeUrl)
{
//RegEx to Find YouTube ID
Match regexMatch = Regex.Match(youTubeUrl, "^[^v]+v=(.{11}).*",
RegexOptions.IgnoreCase);
if (regexMatch.Success)
{
return "http://www.youtube.com/v/" + regexMatch.Groups[1].Value +
"&hl=en&fs=1";
}
return youTubeUrl;
}
public bool CheckDuplicate(string youTubeUrl)
{
bool exists = false;
SqlCommand cmd = new SqlCommand(String.Format("select * from YoutubeVideo where url='{0}'", youTubeUrl), con);
using (con)
{
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
exists = (dr.HasRows) ? true : false;
}
return exists;
}</code>
from ablove code i get youtube video in datalist but when i click to it it plays as it is in 200px*200px.
I would do this differently.
Personally, I'd not embed the video as this is the problem! Instead, embed a picture of the video or similar, the onclick then loads the appropriate video in a new window.
Update your template too
<ItemTemplate>
Description:
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
<br />
<br /><br />
</ItemTemplate>
You may also need to update your Insert command as it may allow for SQL injection.

Repeater displaying only first record with CSS

In the below code by using DIV tag repeater is displaying only first one record retrieved from database. By removing DIV tag mbody everything is working fine. But to align the format of the script I started to use this DIV tag but I am unable to view add records. Please check where the error is at.
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="1000" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger controlid="Timer1" eventname="Tick" />
</Triggers>
<ContentTemplate>
<asp:Repeater ID="Shout_Box" runat="server">
<ItemTemplate><div id="mbody">
<%# DataBinder.Eval(Container.DataItem, "Message") %>
</div> </ItemTemplate>
</asp:Repeater><div id="sbox_button">
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /></div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
<ContentTemplate><div id="sb_text"><asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Wrap="true" Width="400" Height="60" /></div></ContentTemplate>
</asp:UpdatePanel>
In the above code 1 repeater, 1 button and 1 textbox are used. By adding text to the textbox and clicking button the textbox's value goes to database and retrieved by using timer. This script is a kind of chat script. But using DIV tag I am unable to display all records :-(
Server side code
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Timer1_Tick(object sender, EventArgs e)
{
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=chatserver;" + "UID=root;" + "PASSWORD=*****;" + "OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
try
{
MyConnection.Open();
OdbcCommand cmd = new OdbcCommand("Select message from shoutbox", MyConnection);
OdbcDataReader dr = cmd.ExecuteReader();
ArrayList values = new ArrayList();
while (dr.Read())
{
string ep = dr[0].ToString();
values.Add(new PositionData(ep));
Shout_Box.DataSource = values;
Shout_Box.DataBind();
}
TextBox1.Text = "";
}
catch
{
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=chatserver;" + "UID=root;" + "PASSWORD=*****;" + "OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
OdbcCommand cmd = new OdbcCommand("INSERT INTO shoutbox(name, message)VALUES(?, ?)", MyConnection);
cmd.Parameters.Add("#email", OdbcType.VarChar, 255).Value = "tick";
cmd.Parameters.Add("#email", OdbcType.Text).Value = TextBox1.Text;
MyConnection.Open();
cmd.ExecuteNonQuery();
MyConnection.Close();
TextBox1.Text = string.Empty;
UpdatePanel2.Update();
}
Move the databinding out of the while loop:
while (dr.Read())
{
string ep = dr[0].ToString();
values.Add(new PositionData(ep));
}
Shout_Box.DataSource = values;
Shout_Box.DataBind();
It does not make any sense to bind the data after reading every value.

Resources