Showing posts with label created. Show all posts
Showing posts with label created. Show all posts

Wednesday, March 28, 2012

Ajax Beta V.1: Strange behaviour with treeview inside the update panel (Again!)

I have a treevew control ( with dynamically created nodes) that was working great with July CTP. The control no longer works with beta any more:

1. Does not maintain the expanded state during ajax post back ( the nodes expand collapse unexpectly).

2. Strange behaviour if nodes are dynamically populated. This bug was present with the earlier atlas CTP's but was fixed with July CTP.

I have to use the same work around referenced in post:http://forums.asp.net/thread/1203662.aspx

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

Similar issue, I didn’t want the tree to update always. The workaround that I am using is ,

Put tree in update panel (with conditional update).

- Add "TreeNodePopulate" event as a trigger in your update panel

- Turn off the client behaviour of tree expand ( putPopulateNodesFromClient = false ) and let atlas take care of it.

- Use Populate on demand = true.

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

Is any body else is having similar problem?

You might want to look at the CSS Adapters Beta 3 - they have what appears to be a 'ajaxified' treeview control that does not do full postbacks and retains viewstate on the client side... However, warning... if you do not need the other adaptewrs do not install them in your project as they override everything automatically and there is no method I know of to not allow the adapters controls it targets dynamically or explicitly...

The cool thing though is they provide all the source for it - so it may mean you can at least write an custom extender control for treeview that will integrate nicely with ajax...

Just a suggestion - and as usual unsure if I ever know what I am talking about...

Ajax Beta 2 in medium trust...... is it possible ?

Hi all !

I'm french so excuse me by advance for my english...

I have created a photo gallery with ajax beta 2 and then, i've the medium trust security exception problem like à lot of people.

My webhoster (aspnix.com) use the medium trust security level like others and i don't want how to do... I made the time test at this adress but doesn't work...

http://www.ktchup.info/Default.aspx


Anyone has an idea ?

Thanks !

hello.

you acn only do that if the extensions dll is on the GAC. if you're putting in the bin, i think that your web app has to have full trust.

AJAX based Web service authentication issue

Hi, I have created a webservice for putting overlays on googlemap. I am using scriptmanager to generate java proxy class. Everything works as expected as long as I use localhost in the url e.g.http://localhost/test.aspx orhttp://localhost/map.asmx/js but if I use the actual domain name then it don't work anymore e.g.http://www.test.com/test.aspx orhttp://www.test.com/map.asmx/js. In case of IE7 i get script error 'test is undefined' and in case of Firefox, I get authentication failed. The result is same whether I run it on the server or on the client. I have tried every possible thing that I can think of. Environment is Win 2003 and IIS 6.0. Framework 2.0 is enabled in the web services entensions. I am using windows integrated authentication and anonymous access is also enable. I am new to ajax world and trying hard for last 2 days to solve this problem. Please help me. Thanks a lot

Hi,

Can you directly browse to http://www.test.com/map.asmx/js. and does that download the Script Proxy ?

Also , can you take a look at the IIS Logs to understand the behavior on the server when you browse to the page ?

Go to Start --> Run -->Type in "LogFiles"

In the folder that opens up , go inside W3SVC1.

Take a look at the File exmmddyy.log and paste the lines that havemap.asmx/js. here.


Thanks for quick response. When I directly browse to .../js in IE7, i get 500 internal error whereas in case of Firefox, it prompts to download a file and the contents of the file are: "{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}".

No such folder "W3SVC1" exists under LogFiles ... only following folders are present there "Cluster, HTTPERR, ShutDown" and in there I am not able to find anything related to my issue.

Please let me know what next I should do? Thanks


Hi,

HttpPost andHttpGet for webservices is disabled by default in ASP.net 2.0

See if you can find the following snippet in your web.config , if it doesnt exist, add it under the <System.Web> Tag

<webServices>
<protocols>
<add name="HttpSoap1.2"/>
<add name="HttpSoap"/>
<add name="HttpPost"/> // uncomment this
<add name="HttpGet"/> // uncomment this
<add name="HttpPostLocalhost"/>
<add name="Documentation"/>
</protocols>
<soapExtensionTypes>
</soapExtensionTypes>
<soapExtensionReflectorTypes>
</soapExtensionReflectorTypes>
<soapExtensionImporterTypes>
</soapExtensionImporterTypes>
<wsdlHelpGenerator href="http://links.10026.com/?link=DefaultWsdlHelpGenerator.aspx"/>
<serviceDescriptionFormatExtensionTypes>
</serviceDescriptionFormatExtensionTypes>
</webServices>

Hope this helps


Read this KB article about Protocols and web services

HOW TO: Limit the Web Services Protocols that a Server Permits

http://support.microsoft.com/?id=815150


Yes, it was not there and I copied it under system.web tag but the issue is still there. There is also an <httpHandles> tag under system.web. I am pasting the lines from my web.config related to ajax. May be it will give further clue. Please let me know if u see something wrong there or what should I do next. Thanks a lot.

--------

<configSections>
<sectionGroupname="system.web.extensions"type="System.Web.Configuration.SystemWebExtensionsSectionGroup,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35">
<sectionGroupname="scripting" type="System.Web.Configuration.ScriptingSectionGroup,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35">
<sectionname="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">
<sectionname="jsonSerialization"type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" requirePermission="false"allowDefinition="Everywhere" />
<sectionname="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>
<sectionGroup name="applicationSettings"type="System.Configuration.ApplicationSettingsGroup, System,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="wwwroot.Properties.Settings"type="System.Configuration.ClientSettingsSection, System,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"requirePermission="false" />
</sectionGroup>
</configSections>

<system.web>

<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" />
<addverb="GET,HEAD" path="ScriptResource.axd"type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions,Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"validate="false" />

</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-ISAPI-2.0" />
<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" />
<addname="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>

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


I have found the iis logfiles and the directory 'W3SVC1' ... this directory is present in another partition because of setting different path for logging from IIS console.

Below are the lines related to this webservice:

this is the line when called with the following url : http://localhost/WebServices/WSGoogleMaps.asmx

2007-02-22 17:06:54 127.0.0.1 GET /webservices/wsgooglemaps.asmx/js - 80 - 127.0.0.1 Mozilla/5.0+(Windows;+U;+Windows+NT+5.2;+en-US;+rv:1.8.1.1)+Gecko/20061204+Firefox/2.0.0.1 200 0 0

and this is the line when called with the following url: http://mytest.server.com/WebServices/WSGoogleMaps.asmx

2007-02-22 18:15:27 192.167.1.273 GET /WebServices/WSGoogleMaps.asmx/jsdebug - 80 - 132.136.112.84 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.1;+InfoPath.2;+.NET+CLR+2.0.50727;+.NET+CLR+1.1.4322) 500 0 0

I have tried it on the server itself as well. If I use domainname then it is giving 500 internal error in IE7 or authentication failed in Firefox. This is the line when called from the server itself using domain name:

2007-02-22 16:41:04 192.167.1.273 GET /WebServices/WSGoogleMaps.asmx/jsdebug - 80 - 192.167.1.273 Mozilla/5.0+(Windows;+U;+Windows+NT+5.2;+en-US;+rv:1.8.1.1)+Gecko/20061204+Firefox/2.0.0.1 500 0 0

I simply don't understand that how same code on the same machine works with localhost in the url but gives error when called with domain name in the url. I am totally lost. Please help me solve it ... I need to solve it urgently. Thanks.


Hi there,

We are experiencing the same issue that seems to do with the domain name causing the authentication error in some environments. Did you ever get a resolution to this issue?

AJAX Baby Steps - removing an item

i am working on my first little ajax project.

Basically i have no idea how to start. I created a AJAX enabled website and i have a simple page on there that basically has a list of items taken from a Class thats stored in the session.

So I have

1 Gridview that bases its DataSource to a Dataset i create from a object (just a class that contains an array list)

2. I have methods in place to loop through the array list, create a datatable and bind it to the gridview

3. I have a method that also removes a selected item from a dataset and refreshes the gridview its a "remove" button.

I would like to have AJAX handle the removal of items (for now, eventually i want the whole thing ajax enabled) but just to start i want to just activate my Remove method from ajax.

But i dont know where to go from here.

So what do i have to do to call my method via AJAX ?

Any advice or help appreciated!

thanks

mcm

well i seem to have figured it out although i dont know what i did or how it works!

I added the ScriptManager tag to the page.

I added an UpdatePanel surrounding my Gridview,

and now my REMOVE buttons work without postbacks!

Holy Momma! How did it do it?!? I thought i'd have to be writing javascript and hooking into new events , etc.

is it REALLY all this easy?

mcm


Yep, it can really be that easy. caveat, though; the UpdatePanels can get pretty heavy in terms of resource requirements if you use them extensively, and there are also issues with certain combinations of controls (witness the volume on the forum of "Update panel and my..." posts. For simple things like you're describing, they work very well, though.

great! So now that i have seen how easy it "can be". I do have a couple more questions.

I created a sample AJAX enabled site to test this bin and it works GREAT im so impressed with myself.

But how complicated is it going to be to make this a component. My idea for the site is to use Master Pages (another first for me)

and down the left side this "component" will sit. I still dont know wether to make it a component or just a content page.

There will be a repeater or a formView on the right with products to add to the bin. I want those to be ajax enabled too. Is it hard to make different elements in different content pages "speak" to each other? Really all im doing (as stated in the first post) is adding items to a Collection stored in a Session Variable (using a facade pattern with a SessionManager class)

Also. I am using the new Web Application templates to build my stuff (from ScottGu's blogs) Can i switch this AJAX enabled site to be a WEb Application and keep the functionality?

thanks,

mcm

Monday, March 26, 2012

Ajax asynchronous postback

Hi all,

I have created a web page with ajax support. In that i have two buttons and three textbox.

All the three textboxes having required field validator attached to them. Now while i am trying to do asynchronous postback it is not possible for me because the required field validator prompts me to enter values. Is there any way to get rid of this...

I would like to do asynchronous postback even though ther are validators on the page

Do u set the same value to propertie ValidationGroup for validators and the button that cause the validation?


 This will not cause validation :
 <asp:button ID="someButton"CausesValidation="false" runat="server" />

Hi SathishRaja,

My understanding of your issue is that you want to get rid of the validation when click the button which will normally fire the validators. If I have misunderstood, please feel free to let me know.

As far as I know, there are three methods to achieve this list below:

Solution 1


Thanks Solution 2 is Working fine for me.

ajax animation extender

hi..

im new to asp ajax..i created image dynamically...and if i click the image panel should be displayed by using animation extender..

i have to write the animation extender in java script...by getting the image ID from code behind...is it possible...


Hi Rajukv,

I think you should better set the AnimationExtender's TargetControlID on the server side. For example:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">protected void Page_Load(object sender, EventArgs e) { Image myImage = new Image(); myImage.ID = "myimage"; myImage.ImageUrl = "~/pic/upg_HomeBasic.jpg"; this.Panel1.Controls.Add(myImage); this.AnimationExtender1.TargetControlID = "myimage"; }</script><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:ScriptManager> <asp:Panel ID="Panel1" runat="server" Height="300px" Width="600px"> <ajaxToolkit:AnimationExtender ID="AnimationExtender1" runat="server"> <Animations> <OnHoverOver> <Parallel Duration=".1" fps="50"> <Resize Width="250" Height="250" /> </Parallel> </OnHoverOver> <OnHoverOut> <Parallel Duration=".1" fps="50"> <Resize Width="50" Height="50" /> </Parallel> </OnHoverOut> </Animations> </ajaxToolkit:AnimationExtender> </asp:Panel> </form></body></html>

I hope this help.

Best regards,

Jonathan


Thank u Jonathan .

i got it by using ModelpopUp with animation...by taking Modelpopup TargetControlID=hiddenbutton


ajax and webservices...

I have created a dataset. Each method of the tableadapter shows the right data when I preview it at design time.
However, when I load the page I get the value in both dropdownlists: [method error 500]

If I step throught the code, the webmethod is not hit even though I put a breakpoint on it (or is that normal?)

Here's my code:


.ASPX

<asp:DropDownList ID="ddlCountry1" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="ddlLocalCity" runat="server">
</asp:DropDownList>

<cc1:CascadingDropDown ID="CascadingDropDown1"
runat="server"
TargetControlID="ddlCountry1"
Category="CountryName"
prompttext="Select country"
ServicePath="LocalCities.asmx"
ServiceMethod="GetCountries">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="CascadingDropDown2"
runat="server"
TargetControlID="ddlLocalCity"
Category="CityName"
prompttext="Select city"
ServicePath="LocalCities.asmx"
ServiceMethod="GetCitiesForCountry"
LoadingText="Loading...">
</cc1:CascadingDropDown>

Local.vb

<WebMethod()> _
Public Function GetCountries(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim countryAdapter As CountryMainCitiesTableAdapters.CountriesTableAdapter = New CountryMainCitiesTableAdapters.CountriesTableAdapter
Dim countries As CountryMainCities.tblCountriesDataTable = countryAdapter.GetData
Dim values As New List(Of CascadingDropDownNameValue)
For Each dr As DataRow In countries
Dim CountryName As String = CType(dr("CountryName"), String)
Dim countryId As Integer = CType(dr("CountryID"), Integer)
values.Add(New CascadingDropDownNameValue(CountryName, countryId.ToString))
Next
Return values.ToArray
End Function

<WebMethod()> _
Public Function GetCitiesForCountry(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim kv As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
Dim countryId As Integer
If (Not kv.ContainsKey("CountryID") _
OrElse Not Int32.TryParse(kv("CountryID"), countryId)) Then
Return Nothing
End If
Dim cityAdapter As New DataTable

Dim adapter As CountryMainCitiesTableAdapters.CountryMainCitiesTableAdapter = New CountryMainCitiesTableAdapters.CountryMainCitiesTableAdapter
Dim cityTable As CountryMainCities.tblCountryMainCitiesDataTable = adapter.GetDataByCountryID(countryId)
Dim values As New List(Of CascadingDropDownNameValue)
For Each dr As DataRow In cityTable
values.Add(New CascadingDropDownNameValue(CType(dr("CityName"), String), dr("CityID").ToString))
Next
Return values.ToArray
End Function

Try to follow up the following suggestions to fix the famous Method Error 500 for reference.
1.Try to read this thread -http://forums.asp.net/1476672/ShowThread.aspx#1476672
2.Try to write a web method in behind code to call web service as the following
???Country:<asp:DropDownList ID="ddlCountry" runat="server">
???</asp:DropDownList>
???<AjaxControls:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="ddlCountry" Category="Country" ????LoadingText="Loading....." ServiceMethod="GetCountries" BehaviorID="CascadingDropDown1" PromptText="- select country -">
???</AjaxControls:CascadingDropDown
???[WebMethod]
???[ScriptMethod]
???public CascadingDropDownNameValue[] GetCountries()
???{
???????WebService ws = new WebService();
???????return ws.GetCountries();
???}
Wish the above can help you.

The other thread did not help me a lot. But I changed some code, however I still receive the error [method 500]

and if I add the attribute
ServicePath="default.aspx.vb" to CascadingDropDown2 I receive the error [method 404]

The code-behind method GetCitiesForCountry is never hit...

DEFAULT.ASPX

<asp:DropDownList ID="ddlCountry1" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="ddlLocalCity" runat="server">
</asp:DropDownList>

<cc1:CascadingDropDown ID="CascadingDropDown1"
runat="server"
TargetControlID="ddlCountry1"
Category="CountryID"
prompttext="Select country"
ServicePath="LocalCities.asmx"
ServiceMethod="GetCountries">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="CascadingDropDown2"
runat="server"
TargetControlID="ddlLocalCity"
ParentControlID="ddlCountry1"
Category="CityID"
prompttext="Select city"
ServicePath="default.aspx.vb"
ServiceMethod="GetCitiesForCountry"
LoadingText="Loading...">
</cc1:CascadingDropDown>

DEFAULT.ASPX.VB

<WebMethod(), Microsoft.Web.Script.Services.ScriptMethod()> _
Public Function GetCitiesForCountry(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim kv As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
Dim CountryID As Integer
If (Not kv.ContainsKey("CountryID") _
OrElse Not Int32.TryParse(kv("CountryID"), CountryID)) Then
GlobalFunctions.ReportError("CountryID: ", "WHOOPS")
Return Nothing
End If
GlobalFunctions.ReportError("CountryID: ", CountryID.ToString)
Dim cityadapter As CountryMainCitiesTableAdapters.CountryMainCitiesTableAdapter = New CountryMainCitiesTableAdapters.CountryMainCitiesTableAdapter
Dim cities As CountryMainCities.tblCountryMainCitiesDataTable = cityadapter.GetDataByCountryID(CountryID)
Dim values As New List(Of CascadingDropDownNameValue)
For Each dr As DataRow In cities
GlobalFunctions.ReportError("CityID: ", dr("CityID").ToString)
values.Add(New CascadingDropDownNameValue(CType(dr("CityName"), String), dr("CityID").ToString))
Next
Return values.ToArray
End Function

Saturday, March 24, 2012

Ajax and UserControl from scratch

Hi all,

Iam building a web custom control from scratch ir no server control is used ..so how i implement ajax in this.

Example:i created a tree view using <ul><li> and when i clicked the node i call a javascript function for filling the data now where i write this function so that every call to this function is asynchronous

please help me out

Hi Spanco,

Partial Update Treeview is a complex and big project, so sorry we cannot provide a working sample as what you want to get.However, in my opnion, I think you may use Ajax + Div + WebService. Fortunately, I have found some urls related what you are concerning. Here they are:

1.http://www.codeproject.com/useritems/TreeViewAjax.asp

2.http://www.codeproject.com/Ajax/IntroAjaxASPNET.asp

3. http://ajaxaspects.blogspot.com/2006/01/tree-view-ajax-control.html The sample url:http://www.mathertel.de/AjaxEngine/S03_AJAXControls/TreeView.aspx . You can get the source code here and I hope that you can benefit from it. This sample is using Ajax + XML +WebService.

This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

I hope this help.

Best regards,

Jonathan

AJAX and Master Pages

I seem to be having some trouble using AJAX and the ControlToolkit with Master Pages.

Just to make sure, I created a new website based on the AJAXControlToolkit template.

and a simple default.aspx - it only has a scriptmanager, panel ( with some text in it), linkbutton and AnimationExtender.

it is set to show/hide the panel when the linkbutton is hovered on - this works as expected.

Then, I create a masterpage.master file and a new WebForm based on this master file.

using the same markup fro the default.aspx page, I get a page that looks the same as default.aspx

but does not show/hide the panel and has a Javascript error as follows:

Sys.ArgumentException:

AjaxControlToolkit.Animation.Animation.set_animationTarget requires the ID of a Sys.UI.DomElement or Sys.UI.Control.

No element or control could be found corresponding to 'Panel1'

Parameter name: id

It seems as though the controls are being renamed and I might need to change the TargetControlID on PageLoad or something.

Any ideas would be appreciated.

Mike

This is the difference between server ID and client ID. The .ClientID property of a control can be used to get its client ID and should help here.

Ajax and JavaScript Arrays

Does anyone know why a new Array Contains data when just created when a script manager is running on the page... I do the following code:

<script language="javascript">
var myArray = new Array();
for (x in myArray)
{
document.write(myArray[x])
}
</script>

And get the output: function (index) { this.splice(index, 1); }

WHY!?!?!??!!?

Hi,

this happens because Array is extended through the prototype object, i.e.

Array.prototype.splice = ...

The solution is to extend Array using "type" methods:

Array.splice = ...

I believe this will be fixed in the next release.


hello.

As always, Garbin is correct. btw, i'd just like to add that, in my opinion, the for each usage in arrays which expects to get only the elements is just a side effect of the way foreach works (in other words, i think that even though everyone uses that for getting the elements of an array, it's not what it was meant for)


Actually you are absolutely right. I have solved the problem and what i did was just remove the:

for (x in Array)

and replace it with:

for (x = 0; x < Array.length; x++)

this seemed to fix it right up. It wasn't the fact that the array actually had those values in it. It's just somehow they array accessed those things when used in the for each statement... As gabin said it has to do with prototyping, which i was not familiar with. Thanks for the help guys, and the explanation.


hello again.

btw, i do believe that if you go the other way around, you'll have amore performant solution (ie, instead of goin from 0 to length, do it the other way around - if you can, of course).


I can't. It seems to always be populated with that data otherwise... I don't see why it would cause better performance. My array lengths are exact and not allocated longer then there last bit of information.

hello.

well, it all dependes on the number of items. check this and let me know:

http://www.devpro.it/examples/loopsbench/

Ajax and HttpModules help needed

Hello, Smile

I created a HttpModule that uses an IHttpModule to add content to the start of the webpage, but i get the error of:

Sys.webforms.pagerequestmanagerparsererrorexception: The message received from the server could not be parsed. Common causes for this error are when the response if modified by calls to response.write(), response filters, httpmodules, or server trace is enabled. Details: Error parsing near '<h4>Request Begins

I tried to put the AJAX ScriptModule before and also after but I still cannot get this to work

Is there something i need to do to make this work, or am I just out of luck because you cannot change or add to the page due to AJAX

The code I am using is:


Implements IHttpModule


Public Sub Dispose() Implements IHttpModule.Dispose
' add clean-up code here if required
End Sub

Public Sub Init(ByVal app As HttpApplication) Implements IHttpModule.Init

AddHandler app.BeginRequest, AddressOf MyBeginRequest
End Sub

Public Sub MyBeginRequest(ByVal s As Object, ByVal e As EventArgs)
Dim app As HttpApplication
app = CType(s, HttpApplication)

app.Response.Write ("<h4>Request Begins Here...</h4>")
End Sub

Hi Tdar,

Check out thishttp://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx

Hope this helps,

Wednesday, March 21, 2012

Ajax and dynamically created images

Hi all,

I have a page that display a large dynamically created image (server side script) that can take a while to be generated (say about 2 seconds). Pressing a button I want the image to be refreshed.

I included the image and the button in a UpdatePanel to avoid flicker, but I don't take the effect I want as images are loaded asynchronously by the browser after the UpdatePanel completes.

Is there a solution to avoid this?

Thanks in advance

Here's the simple code I used:

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title></title>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:ScriptManagerID="ScriptManager"runat="server">

</asp:ScriptManager>

<asp:UpdatePanelID="UpdatePanelMain"runat="server">

<ContentTemplate>

<imgalt=""src="testimage.aspx?<%=DateTime.Now()%>"/>

<asp:ButtonID="ButtonRfreshImage"runat="server"Text="Refresh"/>

</ContentTemplate>

</asp:UpdatePanel>

</div>

</form>

</body>

</html>

Hi,

I think you need to block the execution of button click event until the image is generated successfully so that the changes can be reflected on the client.

For instance:

btnClick()

{

generateImage();// call this method synchronously

}

Hope this helps.


This is what I do, my code was only an example to demonstrate the behaviours.

What happens in any case is that, if the image is big enough and the connection is slow, the page will be refreshed before the image is completely received because the browser download it asynchronously.

I solved this using two images, one invisible and the other as a placeholder: I refresh the invisible image and when it is complete I reassign the .src of the placeholder image to load the some URL: the file is now in the cache and it happens immediately .... but I think it's strange Ajax doesn't support this directly.

Ajax and Dynamically created controls.

I have an app where I add images to a panel based on what a user selects from a drop down list. Under internet explorer and opera it works fine. but the html code generated in firefox and netscape is missing the events. When I debug with IE or OPERA as default browser in vs 2005 events are fired. When Netscape or Firefox are set as default events (for the images) are not fired. I looked at the code being generated by the server and there are no events in the html code for the images. Here is what I get.

<li class="zipitem"><input name="zipselect1$ziprepeater$ctl01$selectbtn"id="zipselect1_ziprepeater_ctl01_selectbtn"class="imagebtn"src="images/selectbtn.gif"alt="Select"style="border-width: 0px;"type="image"><span id="zipselect1_ziprepeater_ctl01_ziplbl">12836</span></li><li class="zipitem"><input name="zipselect1$ziprepeater$ctl02$selectbtn"id="zipselect1_ziprepeater_ctl02_selectbtn"class="imagebtn"src="images/selectbtn.gif"alt="Select"style="border-width: 0px;"type="image"><span id="zipselect1_ziprepeater_ctl02_ziplbl">12851</span></li>
<li class="zipitem"><input name="zipselect1$ziprepeater$ctl03$selectbtn"id="zipselect1_ziprepeater_ctl03_selectbtn"class="imagebtn"src="images/selectbtn.gif"alt="Select"style="border-width: 0px;"type="image"><span id="zipselect1_ziprepeater_ctl03_ziplbl">12852</span>
this is just a code scrap. The page looks fine in all browsers but the Mozilla browsers dont work. You should be able to click on the images which takes and adds the zipcodes the images represent into a gridview. As I said works in IE and Opera fine.
 
 
 

See this is Browser compatibility issue....

Can you post some code details so it will help..

Which version of Firefox you used...

I suggest try yo use latest version...


It is a browser issue? I thought asp.net server side created the code for each browser. Any way if I.E worked the way it should I would not need Ajax to solve this problem. It is the only browser of the four I have tested that causes the screen to flash when clicking on the images. of course I could have some setting wrong which IE requires that the others don't.

The follow code produces a number of images on the page. When an image is clicked it gets put into a data grid.

see first post for code scrap generated for mozilla browsers . As can be seen there there is no event code created for the images.

As for code here is html source

<%@. Control Language="c#" AutoEventWireup="false" Codebehind="zip_selector.ascx.cs" Inherits="active.UserControls.zip_selector" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%
<br>
<div id="div_selectedzip">
<asp:label runat="server" id="lblSelZip"> Set of Selected Zipcodes: </asp:label><asp:button id="btnRemoveAll" runat="server" text="Remove All" visible="False"></asp:button><asp:repeater id=selectedzip runat="server">
<headertemplate>
<ul style="list-style-type: none">
</headertemplate>
<itemtemplate>
<li class="selectedzipitem">
<asp:label id="Label2" runat="server"><%#DataBinder.Eval(Container.DataItem, "zip_code") %></asp:label>
<asp:linkbutton id="removelnk" runat="server" commandname='<%# DataBinder.Eval(Container.DataItem, "zip_code") %>'>Remove</asp:linkbutton
</li>
</itemtemplate>
</asp:repeater>
<div style="CLEAR: both"></div> <!-- This is to make Opera load correctly for fieldsets -->
</div>
<br>
<div id="div_cntyzip">
<div id="instructTxt"><p>Enter one or
more zip codes in the text box separated by commas. Or you can add to set of selected zip
codes from a county. If you are interested in one of the <a onclick="window.open('glossary.htm', 'Glossary', 'width=432,height=270,toolbar=0,scrollbars=1,screenX=200,screenY=200,left=200,top=200')" href="http://links.10026.com/?link=javascript:void(0)" >non-standard zipcodes</a>, type one or more of the
following values separated by commas: <b>invalid,
illegible, unreported, irregular, or private</b>.</p></div>
<asp:label id="zipErrMsg" runat="server" forecolor="Red" visible="False">* Error:</asp:label>
<span>Zip Code:</span><asp:textbox id=txtZip runat="server"></asp:textbox><asp:button id=btnSelectZip runat="server" text="Add to Set"></asp:button>
<asp:Button id="btnAddAllZip" runat="server" Text="All NYS Zipcodes"></asp:Button><br>
<div style="DISPLAY: inline; WIDTH: 70px; HEIGHT: 15px" ms_positioning="FlowLayout">OR</div><br
<span>Add to Set of Selected Zipcodes from County: </span><asp:dropdownlist id=cntyzipddl runat="server" autopostback="True"></asp:dropdownlist>
<asp:repeater id=ziprepeater runat="server" OnItemCommand="ziprepeater_ItemCommand1" >
<headertemplate>
<ul style="list-style-type: none">
</headertemplate>
<itemtemplate>
<li class="zipitem">
<asp:imagebutton id="selectbtn" runat="server" cssclass="imagebtn" alternatetext="Select" imageurl="../images/selectbtn.gif" commandargument='<%#DataBinder.Eval(Container.DataItem, "cnty_code") %>' commandname='<%#DataBinder.Eval(Container.DataItem, "zip_code") %>'></asp:imagebutton>
<asp:label id="ziplbl" runat="server"><%#DataBinder.Eval(Container.DataItem, "zip_code") %></asp:label>
</li>
</itemtemplate>
<footertemplate>
</ul>
<div class="spacer"> </div>
</footertemplate>
</asp:repeater>
<div style="CLEAR: both"></div> <!-- This is to make Opera load correctly for fieldsets -->
</div>
<br
here is code behind page in c#

namespace active.UserControls
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using active.DataAccessLayer;
using active.Common;

/// <summary>
/// Summary description for zip_selector.
/// </summary>
public class zip_selector : System.Web.UI.UserControl
{
#region Properties
protected System.Web.UI.WebControls.Repeater ziprepeater;
protected System.Web.UI.WebControls.Repeater selectedzip;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label zipErrMsg;
protected System.Web.UI.WebControls.Label lblSelZip;
protected System.Web.UI.WebControls.TextBox txtZip;
protected System.Web.UI.WebControls.Button btnSelectZip;
protected System.Web.UI.WebControls.DropDownList cntyzipddl;
protected System.Web.UI.WebControls.Button btnRemoveAll;
protected System.Web.UI.WebControls.Button btnAddAllZip;
protected bool bBadZipFound=false;
private int MAXZIP;

private int MAXZIPCOUNT
{
get {return 300;}
set {MAXZIP = value;}
}

public bool All_ZIP_SELECTED
{
get
{
object o = ViewState["All_Zip_Selected"];
if (o == null)
return false;
else
return (bool)o;
}
set { ViewState["All_Zip_Selected"] = value; }
}

private string CountyCode
{
get
{
object o = ViewState["CountyCode"];
if (o == null)
return "00";
else
return o.ToString();
}
set { ViewState["CountyCode"] = value; }
}

public DataTable SelectedZipTable
{
get
{

DataTable t = ViewState["SelectedZip"] as DataTable;
if (t == null)
{
t=new DataTable("SelectedZip");
DataColumn dc = new DataColumn("zip_code",System.Type.GetType("System.String"));
DataRow dr = t.NewRow();
t.Columns.Add(dc);
dr["zip_code"] = "None Selected";
ViewState["SelectedZip"] = t;
}

return t;
}
set { ViewState["SelectedZip"] = value; }
}
public bool BadZipFound
{
get
{
return bBadZipFound;
}
}
public event EventHandler BubbleClick;
#endregion

#region Page Events
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
zipErrMsg.Visible = false;
if (!Page.IsPostBack)
{
CountyList lstCounties = Lookups.Counties;

//Filter out the non-standard county codes. All nonstandard counties have a sort_order
//greater than 990.
DataView dv = lstCounties.Tables[0].DefaultView;
dv.RowFilter = "sort_order < 990";
//lstCnty.DataSource = lstCounties;
cntyzipddl.DataSource=dv;
cntyzipddl.DataMember = lstCounties.counties.TableName;
cntyzipddl.DataTextField = lstCounties.counties.cnty_nameColumn.ColumnName;
cntyzipddl.DataValueField = lstCounties.counties.cnty_codeColumn.ColumnName;
cntyzipddl.DataBind();

ListItem item= new ListItem("Select County","00");

cntyzipddl.Items.Insert(0,item);
cntyzipddl.SelectedValue = CountyCode;

BindZipRepeater();
BindSelectedZip();

}

}
protected override void OnPreRender(EventArgs e)
{
if (SelectedZipTable.Rows.Count > 0)
btnRemoveAll.Visible=true;
else btnRemoveAll.Visible=false;
base.OnPreRender (e);
}
#endregion

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
this.cntyzipddl.SelectedIndexChanged +=new EventHandler(cntyzipddl_SelectedIndexChanged);
this.ziprepeater.ItemCommand +=new RepeaterCommandEventHandler(ziprepeater_ItemCommand);
this.selectedzip.ItemCommand +=new RepeaterCommandEventHandler(selectedzip_ItemCommand);
this.btnSelectZip.Click += new System.EventHandler(this.btnSelectZip_Click);
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnRemoveAll.Click += new System.EventHandler(this.btnRemoveAll_Click);
this.btnAddAllZip.Click += new System.EventHandler(this.btnAddAllZip_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

#region User Public Methods

/// <summary>
/// Binds the zip selector datagrid to the results from list of zip codes retrieved by county
/// </summary>
public void BindZipRepeater()
{
DataSet dsZipSelect;
string cnty_cd = CountyCode;
DataTable dt;

dsZipSelect = Lookups.GetZipByCnty(cnty_cd);
dt = dsZipSelect.Tables[0];

//Add the option of selecting all zip codes in county
if (CountyCode!="00")
{
DataRow dr = dt.NewRow();
dr[1]="All County Zip";
dt.Rows.Add(dr);
}
/*//Add the option of selecting all NY zip codes
dr = dt.NewRow();
dr[1]="All NY Zip";
dt.Rows.Add(dr);
*/
ziprepeater.DataSource = dsZipSelect;
ziprepeater.DataMember = "ZipSelect";
ziprepeater.DataBind();

}

public void BindSelectedZip()
{
selectedzip.DataSource = SelectedZipTable;
selectedzip.DataMember = "SelectedZip";
selectedzip.DataBind();

int selectedCount = SelectedZipTable.Rows.Count;
lblSelZip.Text = "Set of Selected Zip Codes (" + SelectedZipTable.Rows.Count + " of " + MAXZIPCOUNT + " Max): ";

}
#endregion

#region Private Methods
private void lstCnty_SelectedIndexChanged(object sender, EventArgs e)
{
ListControl lstCnty = sender as ListControl;
if (lstCnty != null)
{
CountyCode = lstCnty.SelectedValue;
BindZipRepeater();
}
}

private void cntyzipddl_SelectedIndexChanged(object sender, EventArgs e)
{
ListControl lstCnty = sender as ListControl;
if (lstCnty != null)
{
CountyCode = lstCnty.SelectedValue;
BindZipRepeater();
}
}

private void ziprepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
OnBubbleClick(e);
string selectedZip = e.CommandName;
string selectedCnty = e.CommandArgument.ToString();
DataTable dt = SelectedZipTable;
zipErrMsg.Visible=false;
if (!All_ZIP_SELECTED)
{
//the zip is not already been added and the amount of selected zipcodes
//do not exceed MAXZIPCOUNT
if (dt.Rows.Count < MAXZIPCOUNT)
{
if (selectedZip == "All County Zip")
{
//Add all zips in the selected County
AddCountyZips();
}
else
{
AddSelectedZip(selectedZip);
}
}
else
{
zipErrMsg.Text = "You have exceeded the maximum of " + MAXZIPCOUNT.ToString() + " zip codes. Please narrow your search. <BR>";
zipErrMsg.Visible = true;
}
}
else
{
zipErrMsg.Text="All NYS zip codes have been selected. No need to add individual zipcode.<br>";
zipErrMsg.Visible=true;
}
}

private void selectedzip_ItemCommand(object source, RepeaterCommandEventArgs e)
{
string selectedZip = e.CommandName;
DataTable dt = SelectedZipTable;
string selectExpr = "zip_code ='" + selectedZip+"'";
DataRow[] foundRow = dt.Select(selectExpr);
zipErrMsg.Visible=false;

if (foundRow.Length >0)
{
dt.Rows.Remove(foundRow[0]);
if (selectedZip=="All NYS Zip")
{ All_ZIP_SELECTED = false;
}
BindSelectedZip();

}

}
//"Add to Set" button click method
private void btnSelectZip_Click(object sender, System.EventArgs e)
{
OnBubbleClick(e);
zipErrMsg.Visible=false;
//reset the select county table to avoid confusion
CountyCode="00";
cntyzipddl.SelectedValue = CountyCode;
BindZipRepeater();

if (!All_ZIP_SELECTED)
{
//parse and validate zip input string
string [] zips = zipinput_parser();
DataTable dt = SelectedZipTable;

//if valid zips are returned, add to Selected Zip table
if (zips != null)
{
foreach (string zip in zips)
{
//the zip is not already been added and the amount of selected zipcodes
//do not exceed MAXZIPCOUNT
if (dt.Rows.Count < MAXZIPCOUNT)
{
AddSelectedZip(zip);
}
else
{
zipErrMsg.Text = "You have exceeded the maximum of " + MAXZIPCOUNT.ToString() + " zip codes. Please narrow your search.<br>";
zipErrMsg.Visible = true;
break;
}
//blank out the zip textbox for another entry
txtZip.Text="";
} //end of foreach
} //end of if zip length==0

}
else
{
zipErrMsg.Text="All NYS zip codes have been selected. No need to add individual zipcode.<br>";
zipErrMsg.Visible=true;
}
}

public string[] zipinput_parser()
{
// split zip string between commas
string[] splitTxt = txtZip.Text.Split(new char[] {',',' '});
string validZips="";
string badZips="";
zipErrMsg.Text = "* Error: ";
zipErrMsg.Visible=false;
//check blank zip input
if (txtZip.Text == "")
{
zipErrMsg.Text += "Please enter a zip code value. <br>";
zipErrMsg.Visible = true;
}
else
{
string lowerZip;
//txtZip.Text = "";
foreach (string zip in splitTxt)
{
lowerZip = zip.ToLower();
lowerZip = lowerZip.Trim();
if (zip !="")
{
//check it is not one of the non-standard zip code values
if ((lowerZip != "private") &&(lowerZip != "invalid") && (lowerZip != "illegible") && (lowerZip != "unreported") && (lowerZip != "irregular"))
{ //zip code is invalid if zip is alpha or is not 5 digits long
if ((lowerZip.Length != 5)||!Validations.IsNumeric(lowerZip))
{
//zipErrMsg.Text = zipErrMsg.Text + lowerZip;
zipErrMsg.Visible = true;
//txtZip.Text = txtZip.Text + lowerZip + ",";
badZips= badZips + lowerZip + ",";
}
else validZips = validZips + lowerZip + ",";
}
else validZips = validZips + lowerZip + ",";
}
}
if (zipErrMsg.Visible)
{
bBadZipFound=true;
badZips = badZips.Remove(badZips.Length-1,1);
txtZip.Text=badZips;
zipErrMsg.Text = zipErrMsg.Text + badZips + " is not valid.";
if (validZips.Length>0)
{
zipErrMsg.Text += " Valid zips have been added to the selected zip table.";
}
zipErrMsg.Text += "<br>";
}
//remove last comma
if (validZips.Length>0) validZips = validZips.Remove(validZips.Length-1,1);
}
if (validZips =="")
return null;
else return validZips.Split(new char[] {','});

}

public string zipinput_parser(bool validateOnly)
{
// split zip string between commas
string[] splitTxt = txtZip.Text.Split(new char[] {',',' '});
string validZips="";
string badZips="";
zipErrMsg.Text = "* Error: ";
zipErrMsg.Visible=false;
//check blank zip input
if (txtZip.Text == "")
{
zipErrMsg.Text += "Please enter a zip code value. <br>";
zipErrMsg.Visible = true;
}
else
{
string lowerZip;
//txtZip.Text = "";
foreach (string zip in splitTxt)
{
lowerZip = zip.ToLower();
lowerZip = lowerZip.Trim();
if (zip !="")
{
//check it is not one of the non-standard zip code values
if ((lowerZip != "private") &&(lowerZip != "invalid") && (lowerZip != "illegible") && (lowerZip != "unreported") && (lowerZip != "irregular"))
{ //zip code is invalid if zip is alpha or is not 5 digits long
if ((lowerZip.Length != 5)||!Validations.IsNumeric(lowerZip))
{
//zipErrMsg.Text = zipErrMsg.Text + lowerZip;
zipErrMsg.Visible = true;
//txtZip.Text = txtZip.Text + lowerZip + ",";
badZips= badZips + lowerZip + ",";
}
else validZips = validZips + lowerZip + ",";
}
else validZips = validZips + lowerZip + ",";
}
}
if (zipErrMsg.Visible)
{
bBadZipFound=true;
badZips = badZips.Remove(badZips.Length-1,1);
zipErrMsg.Text = zipErrMsg.Text + badZips + " is not valid.";
zipErrMsg.Text += "<br>";
}
//remove last comma
if (validZips.Length>0) validZips = validZips.Remove(validZips.Length-1,1);
}
return validZips;

}
/// <summary>
/// Adds all the zip codes within a county
/// </summary>
private void AddCountyZips()
{
DataSet dsZipSelect;
string cnty_cd = CountyCode;
DataTable dt = SelectedZipTable;
DataTable cntyTable;
string zipCd;
int totalZip;

zipErrMsg.Visible=false;
dsZipSelect = Lookups.GetZipByCnty(cnty_cd);
cntyTable = dsZipSelect.Tables[0];
totalZip = dt.Rows.Count + cntyTable.Rows.Count;
if (totalZip < MAXZIPCOUNT)
{
foreach (DataRow aRow in cntyTable.Rows)
{
zipCd = aRow[1].ToString();
AddSelectedZip(zipCd);
}
}
else
{
zipErrMsg.Text = "You have exceeded the maximum of " + MAXZIPCOUNT.ToString() + " zip codes. Please narrow your search. <br>";
zipErrMsg.Visible = true;
}
}
private void AddSelectedZip(string zipcd)
{
DataTable dt = SelectedZipTable;
string selectExpr = "zip_code ='" + zipcd +"'";
DataRow[] foundRow = dt.Select(selectExpr);
if (foundRow.Length ==0)
{
DataRow dr = dt.NewRow();
dr[0]=zipcd;
dt.Rows.Add(dr);
BindSelectedZip();
}
}

private void btnRemoveAll_Click(object sender, System.EventArgs e)
{
SelectedZipTable.Clear();
zipErrMsg.Visible = false;
All_ZIP_SELECTED = false;
BindSelectedZip();
}

private void btnAddAllZip_Click(object sender, System.EventArgs e)
{
OnBubbleClick(e);
SelectedZipTable.Clear();
AddSelectedZip("All NYS Zip");
All_ZIP_SELECTED = true;
}
protected void OnBubbleClick(EventArgs e)
{
if(BubbleClick != null)
{
BubbleClick(this, e);
}
}
#endregion

protected void ziprepeater_ItemCommand1(object source, RepeaterCommandEventArgs e)
{

}

}
}

None of the click events for the images created on the fly fire as I said in first posting. You can see that the html generated by the server does not have any events.