Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Wednesday, March 28, 2012

Ajax Update Panel not working...

hi,

I am using the below coding in Inline code..

<

body><formid="form1"runat="server"><div> <asp:ScriptManagerID="ScriptManager1"runat="server"></asp:ScriptManager> <asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate>

<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click1"Text="Button"/><asp:LabelID="Label1"runat="server"Text="Label"></asp:Label></ContentTemplate></asp:UpdatePanel>

</div></form>

</

body>

in code behind

protected

voidButton1_Click(object sender,EventArgs e)

{

Label1.Text =

"Refresh at " & DateTime.Now.ToString();

}

But when I run this page and click on the Button The Page is Posted back again and again..

Please Give quick answer it's urgent......

Thanks

Rocky..

Hi,

did you make the necessary changes to the web.config in order to enable ASP.NET AJAX?


yes ,

In web.config i fix

<

xhtmlConformancemode="Legacy"/>

but i still get the problem...


Hi,

did you apply all the other settings? Specialized sections, handlers etc. ?


will you please tell me briefly about all these settings so that my update panel will work...

if possible then code please for web.config file...

Thanks

Rocky


Hi,

please check theonline documentation topic.

As an alternative, you could compare your web.config with the one of the ASP.NET AJAX-enabled website installed as a Visual Studio template, and make the corresponding changes.


Any other setting I have to do except web.config documentation file in the web site and in eb.config??

Thanks

Rocky


Hi,

it should be enough. Be sure that you've referenced the System.Web.Extensions assembly in your website.

AJAX Update Panel and DataGrid

I write code to populate a datagrid with a Datatable stores in a session variable, I put some data in text boxes and click ADD button it stores that data in table and assign that table to a session variable. FINE.

When I click a datagrid item to Edit. Occasionally it says "Index is out of bound...". It is not always and not always with every row of datagrid. I click on another row to edit it works fine.

I do not know what is actually going inside AJAX. because of using AJAX my ADD and EDIT functionality do not refreshes the page but update the content as required.

Any body know that what should I do?

Regards,

Ather Ali Shaikh

I had a similar problem. I found that on every command I had to recreate the dataview (what I was using) where I used the info from the dataview then things were fine but if I didn't I would get out of bound errors as well as other weird messages. I wasn't trying to use the edit feature of the GridView but just displaying info when a link in a the GridView was clicked so you may also run into things I've not yet found. Anyway, hope this helps some.

Hi,

I do not use the Edit template of the datagrid, what I am doing is using template columns contains Edit link button and on capture is command click event on datagrid on Command event handler.

Monday, March 26, 2012

ajax toolkit tags

hi, i was just wondering because as i've seen in the examples in this forum, when adding an ajax toolkit, in the source code, you can see <ajaxToolkit:SomeToolkit> if i am not mistaken. but when i try to drag a toolkit to the page, or add a toolkit, the tag is different, like <cc1:SomeToolkit>. this puts me to confusion and i am worried that if i upload this to my host, it will not be recognized by the host and i will be obliged to change it manually. what if i have 50 pages that uses 5-8 ajax toolkits? its really a hard work. but this is just an example. maybe you guys can shed light on this. thank you.

Refer to the following link to understand where the tagprefix comes from and their significance

http://www.microsoft.com/mspress/books/sampchap/5728d.aspx#124

As to your worry about different tagprefixes causing problem, it is unfounded.

The declaration at the top of your aspx page e.g.

<%@. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>

and the control tagprefix need to match.

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

Other than this all your pages could have different tagprefixes.

Saturday, March 24, 2012

AJAX Timer bug when it updates a panel containing a single Text Box with the characters "&

The Ajax timer seems to have a problem updating a panel what contains a text box that has the characters "<br>\n". Attached is the source code for a very simple page a single multi-line text box where the timer code-behind just assigns the textbox the string "<br>\n". When run, the second update will cause an 500 error from the server.

This error does not happen when the text is something else, say "Hello World".

I assume that the problem is that the sequence "<br>\n" in the text box causes the timer Java Script to break somehow. Anyone knows oh to solve this problem? I am using Ajax 1.0 and the Visual Studio Development Server.

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox> <asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick"> </asp:Timer> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

The code behind for the time update is:

protected void Timer1_Tick(object sender, EventArgs e) { TextBox1.Text ="<br>\n;"; }

Ivan.

I am sorry, the code for the post got mangled but the editor. The code behind for the time update should be:

public partialclass _Default : System.Web.UI.Page {protected void Page_Load(object sender, EventArgs e) { }protected void Timer1_Tick(object sender, EventArgs e) { TextBox1.Text = "<br>\n"; }}

Apparently, the string <br> is detected as a potentially harmfull string. One solution is to HTML encode the string. However, I do need to display the string <br> in the text box, not <br>. The user must be able to edit the HTML code that we will use.

Ivan.


Apparently, the string <br> is detected as a potentially harmfull string. One solution is to HTML encode the string. However, I do need to display the string <br> in the text box, not <br>. The user must be able to edit the HTML code that we will use.

Ivan.

Ajax timeout when debugging ASP.Net code

How can I prevent Ajax timeout errors while debugging my ASP.net code using Visual Studio? My page uses the Timer control, so it should be the cause of the problem.Set the page's ScriptManager property:

AsyncPostBackTimeout

="0"

Ajax time zone bug

there appears to be a bug in the ajax client code. First, try this in javascript:

var testDate = new Date();

var testDateString = testDate.localeFormat("yyyy-MM-ddTHH:mm:ss.fffffffzzz");

I'm in New York, so the value of testDateString = "2007-10-12T12:10:56.34534+4:00" or something like that.


now try doing this in c#

DateTime testDate = DateTime.Now;

testDateString = testDate.toString("yyyy-MM-ddTHH:mm:ss.fffffffzzz");

in this case, the value of testDateString is equal to something like: "2007-10-12T12:10:56.34534-4:00"

now to see some real fun, add this to the above Javascript:

var messedUpDate = Date.parseLocale(testDateString, "yyyy-MM-ddTHH:mm:ss.fffffffzzz");

you'll find that the messed up date is not equal to the original test date. however in c#

DateTimemessedUpDate = Date.ParseExact(testDateString,"yyyy-MM-ddTHH:mm:ss.fffffffzzz",CultureInfo.CurrentCulture.DateTimeFormat);

will yield a date equivalent to testDate.

Is this a bug? or am I misusing/misunderstanding the localeFormat method?

Hi,

I think parseLocal create a date from a localized date string. I think it works only when you do the followings (it is from the documentation):

Remarks

Use the pareseLocale function to create anobject of type Date from a string. If you provide no custom formats,this function uses theSys.CultureInfo.CurrentCulture property to determine the culture value.

To create a date from a locale-specific string that uses the current culture, set theEnableScriptGlobalization property of theScriptManager control totrue. You must also modify settings in the Web.config file so that theculture attribute of the<globalization> section is set toauto.


I don't think this is a localization problem. As you can see by the results of running my code, all the strings do parse correctly as dates, the problem is that the resulting dates are incorrect.


Ok, I see.

First test:

var testDate = new Date();
var testDateString = testDate.localeFormat("yyyy-MM-ddTHH:mm:ss.fffffffzzz");
window.alert( testDateString ); //2007-10-17T10:11:16.0310310-02:00 <-- good
var messedUpDate = Date.parseLocale(testDateString, "yyyy-MM-ddTHH:mm:ss.fffffffzzz");
window.alert( messedUpDate ); //Wed Oct 17 200714:11:16 GMT+0200 (Central Europe Daylight Time) <-- total wrong!!!

Second test:

var testDate = new Date();
var testDateString = testDate.localeFormat("yyyy-MM-ddTHH:mm:ss.fffffff");
window.alert( testDateString ); //2007-10-17T10:13:32.5155155 <-- good
var messedUpDate = Date.parseLocale(testDateString, "yyyy-MM-ddTHH:mm:ss.fffffff");
window.alert( messedUpDate ); //Wed Oct 17 2007 10:13:32 GMT+0200 (Central Europe Daylight Time) <-- also good

Maybe localFormat and parseLocal don't like time zone formatting?!


The issue on the timezone offset was a bug in the javascript date formatting, and will be fixed in the next release. The reason for the discrepancy between parse and format was that parsing didn't have the same bug.

Ajax Tabs OnClientActiveTabChanged error

I have 3 tabs .OnClientActiveTabChanged event I am calling a function which is defined in a separate javascript file.My code works when I have the script code in same file as aspx page. But it throws javascript error when i have the code in a seprate javascript file. "Null is null or not an object" var InslastName = $get(''); var InsFirstName = $get('');The InslastName and InsFirstName are always getting as null when using external script file.I tried to use the ids 'txtInslastName' and 'txtInsFirstName' in the function,but getting error.I have many attributes in my aspx page . So i cant pass ClientID as parameter to the function.Is there any way to get resolve this issue?

Hi Sarathmn,

We cannot use Control.ClientID on a separate js file. Your problem is mainly caused by the ClientID issue. When a TextBox inside a TabPanel, its ClientID looks like this TabContainer1_TabPanel2_TextBox1, so you can find out the real ClientID from the generated HTML code and modify your js functions. Here is the another way which I would prefer.

<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1" OnClientActiveTabChanged="tabChanged">

function tabChanged(sender, args){
tabIndex = sender.get_activeTabIndex();
switch(tabIndex)
{
case 1: myfunction('"<%=TextBox1.ClientID%>"');break;
case 2: myfunction('"<%=TextBox2.ClientID%>"');break;
break;
}
}

myfunction is a function inside the separate js file.

I hope this help.

Best regards,

Jonathan


Thanks Jonathan for your reply.

I have a doubt.

Can I assume that the client side id of the controls inside a TabPanel have "TabContainer1_TabPanel2_" pre-fixed with the actual id?


Hi Sarathmn,

Currently, yes. But if you put the Tab control inside another contol, it is hard to say.

I hope this help.

Best regards,

Jonathan

Wednesday, March 21, 2012

AJAX Tab Control

Hi,

How can I able to check what AJAX Tab Container tab is selected in Code Behind?

thanks,

This works for me

Dim containerIdAsString ="TabContent" & TabContainer1.ActiveTabIndex

Where Tabcontent is the generic name for Tab1, Tab2 etc

AJAX stopped working

So not sure what has happened. All of a sudden all my ajax calls have stopped working. Here's my code for the CalendarExtender

<%@dotnet.itags.org. Page Language="VB" CodeFile="test.aspx.vb" AutoEventWireup="true" Inherits="test" %>
<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1">
</cc1:CalendarExtender>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
</form>
</body>
</html>

----------------------

And here's my web.config file:

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" />
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>

<connectionStrings>
<add name="DBConnString" connectionString="Data Source=(local)\SqlExpress; Initial Catalog=DB;Integrated Security=True;"/>
</connectionStrings>


<system.web>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>

<profile enabled="true" defaultProvider="CustomizedProfileProvider">
<providers>
<add name="CustomizedProfileProvider" connectionStringName="DBConnString" applicationName="FlameNET" type="System.Web.Profile.SqlProfileProvider" />
</providers>
<properties>
<add name="SiteID"/>
<add name="UpdateProfile" />
<add name="FirstName"/>
<add name="LastName"/>
<add name="PhoneNumber"/>
</properties>
</profile
<authentication mode="Forms">
<forms loginUrl="~/login.aspx" />
</authentication>

<authorization>
<deny users="?" />
</authorization
<customErrors mode="RemoteOnly" defaultRedirect="~/errorpage.aspx" >
</customErrors
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>

<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>

<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>

<roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
<providers>
<add name="CustomizedRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="DBConnString" applicationName="FlameNET" />
</providers>
</roleManager>
<membership defaultProvider="CustomizedMembershipProvider">
<providers>
<add name="CustomizedMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="DBConnString" applicationName="FlameNET" minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" />
</providers>
</membership>
</system.web>


<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer
<location path="site">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="register.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="errorpage.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
</configuration>
--------------

For some odd reason, when I click into the textbox the calendar no longer pops up, which it used to. I'm lost here any help will be greatly appreciated! THANKS!

I suggest you download fiddler from http://www.fiddlertool.com/fiddler/ and observe the http traffic.

It should tell you if the call is being made and if any error is being returned.

AJAX SlideShow. Works in IE not FF

Hi,

I am very new to AJAX and upon some research I found a piece of code which does what I wanted but it was in C# so I converted it to VB.NET.

Anyways the code works just fine when I run the webpage in IE but doesn't work in FF and I can't figure out what is it that is going wrong? I was wondering if someone can help me out with it.

Also I was wondering if someone can help me add a checkbox on the form which allows me to turn the slideshow ON/OFF?

I wasn't able to upload a file here so here is the link to my projecthttp://www.patel.com.au/ausshare/slideshow.zip

Hope this makes sense.

Cheers :)

Nirav

First of all, I hope you realize that your project is using ASP.net callbacks and not ASP.net Ajax.

Regardless, the reason it is failing in Firefox is because you are returning filepaths instead of url paths. So a request for the image is made like so:

http://localhost:2032/SlideShow/images\testimage1.jpg . IE is forgivng but Firefox is not.

A quick fix would be to do this

return returnresult.Replace("\", "/")


Thanks Raj. I tried your way but no joy on FF.

Gee Whiz..this is an embarrassing moment. I really thought this was AJAX.

In your openion which one is a better method? AJAX or Callbacks? Also if AJAX is better than can it be implemented on production site since I heard it was in beta.

Would it be possible for you to help me out with converting this to AJAX or even a normal ASP.NET with Javascript slideshow with a checkbox which allows me to turn the slideshow On/Off?

Cheers,

Nirav


Which version u r using now?

Use AJAX RC1 it support for FF also...

Smile


Thanks Chetan.

I am using ASP.NET 2.0 and VB.NET as a language.

I am not allowed to install anynew stuff than a standard build since the website hosting has very strict requirements of using only thing out of the box which MS provided with .NET 2.0 Framework.

Thanks :)


It works in Firefox. I have tested it. Here is the code you have to change:

Public Function GetNextImageUrl() As String
'Return the next image to be displayed
Dim returnresult As String = String.Empty

Dim lastimagepath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "images", m_lastFileName)

If files.Length > 0 Then
Dim index As Integer = Array.IndexOf(files, lastimagepath)

'Making sure that we don't get an index out of bound error when we reach the last photo
If index = files.Length - 1 Then
'If we are at the last image then start over
returnresult = files(0).Replace(AppDomain.CurrentDomain.BaseDirectory, String.Empty)
Else
'If we are not at the last image then continue returning the next one in line
returnresult = files(index + 1).Replace(AppDomain.CurrentDomain.BaseDirectory, String.Empty)
End If
End If

Return returnresult.Replace("\", "/")
End Function

Both callbacks and ASP.net are supported in both browsers. ASP.net Ajax is in RC (release candidate) and will be released soon.


Thanks Ra

Thanks Raj,

That is exactly what I did and it didn't work. I think somehow it wasn't compiled correctly as the breakpoint told me the source is changed and different and the breakpoint was disabled.

Is there a way to clear it?

Cheers :)


Please try recompiling your project then - and remove all breakpoints. Regards.

It's working now thanks a lot Raj.

Now I was wondering if you can help me add a checkbox and which will allow me to Start/Stop the slideshow?

Cheers :)

Ajax SlideShow Help

Can Someon help me to convert C# to Vb this web service code from SlideShow example? I already tried conversion tools and it gives me some errors. Thank You All.

<

scriptrunat="Server"type="text/C#">

[System.Web.Services.

WebMethod]

[System.Web.Script.Services.

ScriptMethod]publicstatic AjaxControlToolkit.Slide[] GetSlides()

{

returnnew AjaxControlToolkit.Slide[] {new AjaxControlToolkit.Slide("images/Blue hills.jpg","Blue Hills","Go Blue"),new AjaxControlToolkit.Slide("images/Sunset.jpg","Sunset","Setting sun"),new AjaxControlToolkit.Slide("images/Winter.jpg","Winter","Wintery..."),new AjaxControlToolkit.Slide("images/Water lilies.jpg","Water lillies","Lillies in the water"),new AjaxControlToolkit.Slide("images/VerticalPicture.jpg","Sedona","Portrait style picture")};

}

</script>

<System.Web.Services.WebMethod()> _

<System.Web.Script.Services.ScriptMethod()> _

PublicSharedFunction GetPictures()As AjaxControlToolkit.Slide()ReturnNew AjaxControlToolkit.Slide() { _New AjaxControlToolkit.Slide("images/Blue hills.jpg","Blue Hills","Go Blue"), _New AjaxControlToolkit.Slide("images/Sunset.jpg","Sunset","Setting sun"), _New AjaxControlToolkit.Slide("images/Winter.jpg","Winter","Wintery..."), _New AjaxControlToolkit.Slide("images/Water lilies.jpg","Water lillies","Lillies in the water"), _New AjaxControlToolkit.Slide("images/VerticalPicture.jpg","Sedona","Portrait style picture")}

End

Function

Ken Tucker:

<System.Web.Services.WebMethod()> _

<System.Web.Script.Services.ScriptMethod()> _

PublicSharedFunction GetPictures()As AjaxControlToolkit.Slide()

ReturnNew AjaxControlToolkit.Slide() { _

New AjaxControlToolkit.Slide("images/Blue hills.jpg","Blue Hills","Go Blue"), _

New AjaxControlToolkit.Slide("images/Sunset.jpg","Sunset","Setting sun"), _

New AjaxControlToolkit.Slide("images/Winter.jpg","Winter","Wintery..."), _

New AjaxControlToolkit.Slide("images/Water lilies.jpg","Water lillies","Lillies in the water"), _

New AjaxControlToolkit.Slide("images/VerticalPicture.jpg","Sedona","Portrait style picture")}

EndFunction

Thank You Ken.


Ken Tucker:

<System.Web.Services.WebMethod()> _

<System.Web.Script.Services.ScriptMethod()> _

PublicSharedFunction GetPictures()As AjaxControlToolkit.Slide()ReturnNew AjaxControlToolkit.Slide() { _New AjaxControlToolkit.Slide("images/Blue hills.jpg","Blue Hills","Go Blue"), _New AjaxControlToolkit.Slide("images/Sunset.jpg","Sunset","Setting sun"), _New AjaxControlToolkit.Slide("images/Winter.jpg","Winter","Wintery..."), _New AjaxControlToolkit.Slide("images/Water lilies.jpg","Water lillies","Lillies in the water"), _New AjaxControlToolkit.Slide("images/VerticalPicture.jpg","Sedona","Portrait style picture")}

End

Function

How can I populate this array dynamically? For example, Read some folder with images and create an array?

ForEach sIn Directory.GetFiles(Server.MapPath("my_vacation"),"*.jpg")

Response.write ( Path.GetFileName(s) )

Next


I saw that you answered the dynamic file issue with

ForEach sIn Directory.GetFiles(Server.MapPath("my_vacation"),"*.jpg")

Response.write ( Path.GetFileName(s) )

Next

But how do I get it to dynamically use a value from an SQL table field.

My images have names such as R12345.jpg, R12345_2.jpg, R12345_3.jpg etc...

The listing_id field value is R12345 which would need to replace the "my_vacation" above.

How can I get this to work?

Thanks for your help!

Mike


Imports System.IO
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyData.ImagePath = Server.MapPath("~/Images")
Dim strUrl As String = Request.Url.ToString

MyData.Url = strUrl.Substring(0, strUrl.LastIndexOf("/")) & "/Images/"
End Sub


<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function GetPictures() As AjaxControlToolkit.Slide()
Dim di As New DirectoryInfo(MyData.ImagePath)
Dim s(di.GetFiles.Length - 1) As AjaxControlToolkit.Slide
Dim x As Integer = 0
For Each fi As FileInfo In di.GetFiles()
s(x) = New AjaxControlToolkit.Slide(MyData.Url & fi.Name, "", Path.GetFileNameWithoutExtension(fi.Name))
x += 1
Next
Return s
End Function
End Class

Public Class MyData
Private Shared _Path As String
Private Shared _Url As String

Public Shared Property ImagePath() As String
Get
Return _Path
End Get
Set(ByVal value As String)
_Path = value
End Set
End Property

Public Shared Property Url() As String
Get
Return _Url
End Get
Set(ByVal value As String)
_Url = value
End Set
End Property
End Class


AWESOME!

How can I get it to retrieve images at a url other that mine, such as:

http://www.xyz.com/images

Thanks,

Mike


If you have ftp access to the images you can try something like this.

<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function GetFtpPictures() As AjaxControlToolkit.Slide()
Dim ftp As FtpWebRequest = WebRequest.Create("ftp://ftp.xyz.com/images")
ftp.Credentials = New NetworkCredential("YourUserName", "YourPassword")
ftp.Method = WebRequestMethods.Ftp.ListDirectory
Dim wr As WebResponse =ftp.GetResponse
Dim sr As New StreamReader(wr.GetResponseStream)
Dim lst As New List(Of String)
Do While sr.Peek > 0
Dim strOut As String
strOut = sr.ReadLine
lst.Add(strOut)
Loop
Dim s(lst.Count - 1) As AjaxControlToolkit.Slide
Dim x As Integer = 0
For Each str As String In lst
Dim i As Integer = str.IndexOf("."c)
s(x) = New AjaxControlToolkit.Slide("http://www.xyz.com/images/" & str, "", str.Substring(0, i))
x += 1
Next
Return s
End Function

Article on how to use photos stored in Flickr in a slide show

http://www.onteorasoftware.com/blog.aspx?BlogID=75


pashaKasim this site may help you. You may already know about it, but there might be someone out there who hasnt run across this tool yet.

http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx

J


Really usefull piece of code.I would like to use a slider control to move across page.For that to be implemented i need to move to the Nth image.Is there a method / way to move to the Nth image.ThanksRain Man Alex