Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# juanwoang 4/16/2009 12:09 PM
Dear all CUYers,

Today I try to implement AjaxDataControls, I feel this is very good. I have successful with adding one control that using ADC into any node (page). But if add two or more than that, an error appears. In this case, only data of final control can be show, and other controls show nothing.

Main problem here is that ADC require only one pageLoad function (in javascript) for a single page. But with my implementation, each control have one pageLoad function.

My solution here is write a class, that understand how many time the ADC was called, and which is the final call. But I still not resolve this problem.

Do you have any idea for this?
Thank you much!
# Constructor 4/16/2009 7:24 PM (edited 4/16/2009 7:26 PM)
I have never had any problems. I have read others having lots but I can not repeat the errors.

I do not use any of the Cuyahoga.Web.Extensions either. I just used the ScriptManager in the template and the ScriptManagerProxy in the module that handles the connection to from the module control instance to the ScriptManager on the page.

Really, just try this as I would like to see if it works for other people.

This is what I did.

1) Add (drag and drop it) 'ScriptManager' to template as first control inside the form tag.
(form id="t" method="post" runat="server")
(asp:ScriptManager ID="ScriptManager1" runat="server")(/asp:ScriptManager)

2) Add (drag and drop it) 'ScriptManagerProxy' to first control in module.
(%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CatMod.ascx.cs"  Inherits="Cuyahoga.Modules.CatMod.Web.CatMod" %)
(asp:ScriptManagerProxy runat="server")
(/asp:ScriptManagerProxy)

3) Add an 'UpdatePanel' to your control. Fill it with whatever controls you wish to use/databind.

4) Add an 'UpdateProgress' to the control and associate it with the updatepanel. Add the UpdateProgress message/animation to the UpdateProgress panel.

I have tested many instances on a page and had no trouble! I would like to hear of others experience of this.
Each instance updates firing its own Update Progress panel containing the customary anigif. They each work fine.
# juanwoang 4/17/2009 5:09 AM
Hi Constructor,

I am talking about ADC (http://www.codeplex.com/AjaxDataControls). It require ASP.NET AJAX and I was add it by using Cuyahoga.Web.Extensions.
# Constructor 4/17/2009 11:11 AM
juanwoangHi Constructor,

I am talking about ADC (http://www.codeplex.com/AjaxDataControls). It require ASP.NET AJAX and I was add it by using Cuyahoga.Web.Extensions.

Now I understand. I was thinking that it was MS Ajax that you could not get working.

I will try these controls and see what I find!
# Constructor 4/17/2009 1:00 PM
I have tried this and found that the AjaxDataControls version of the GridView does not seem to access the ScriptmanagerProxy. The standard controls including the GridView all work fine without any issue. I have sent an email to the developers to see if they have any information. I am looking on the forums and the Cuyahoga.Web.Extensions information.

I have not seen these controls before, they look interesting.
# Constructor 4/17/2009 10:13 PM
After a few emails to Sonu Kapoor and a little search I have manages to find a solution. It seems as though I am using a newer version of MS Ajax than was used to build the AjaxDataControls against. If the assembly was compiled against the earlier version, I needed to use binding redirects in the web.config.

So now MS Ajax and these controls are working as I mentioned earlier in this post!

# juanwoang 4/18/2009 8:31 AM
Hi Constructor,

Have you ever used ADC' Repeater? My module has below structure:
C1: Control one that load something, that I using Pager & Repeater
C2: Control tow that load something, that I using Pager & Repeater
...

In one node called N1, I add a few sections that contains my module and using C1, C2 and others. If I only use C1 or C2, it means add only one instance of my module in node, no problem found. But if I add from two sections like above, only the final section can view data. Other one is show nothing.

I found and was ask Sonu, he said "why you do not use one pageLoad function in a page?" (pageLoad is javascript function). I think that I must determine what is the final instance of my module, then I show pageLoad function at this time. But I still have problem.

Do you have any idea?
Thank you in advance
# Constructor 4/19/2009 10:33 PM (edited 4/19/2009 10:38 PM)
I have made a test and a posting on the ADC forum.

Inside a user control I have a GridView, something like this:

function pageLoad(sender, e) {
Cuyahoga.Modules.CatMod.Web.MyWebService.Test_Method(onLoadSuccess);
alert('pageLoad fired.');
}

function onLoadSuccess(result) {
GridView2.set_dataSource(result);
GridView2.dataBind();
alert('onLoadSuccess fired.');
}

The user control populates when there is only one instance added to the page. It does not when there are multiple instances.

In the function onLoadSuccess, when setting the datasource and databinding, the name 'Gridview2' is explicit and therefore the same in all instances rendered to HTML. The last instance of the 'Gridview2' only is populated.

I thought that maybe something like this:

var gridView = $('<%= GridView2.ClientID %>');
gridView.set_dataSource(result);
gridView.dataBind();

The above will not work obviously but it was my first thought. I will keep looking for a solution to this AjaxDataControls specific problem.

Using other controls I do not have any issues at all. Using MS Ajax is as simple as adding the two script managers and you are away. No other configuration required at all.
# Constructor 4/22/2009 8:32 PM (edited 4/22/2009 11:22 PM)
OK, I have found a solution to this. I will try to explain clearly.

The problem was that databinding the Ajax Data Control GridView is done like this:
(I have replaced open and close angle brackets with (( and )) respectively. Why can I not paste code?! :d )
 ((script type="text/javascript"))
    function pageLoad(sender, e) {
        Cuyahoga.Modules.CatMod.Web.MyWebService.Test_Method(onLoadSuccess);
        //alert('pageLoad fired.');
    }

    function PopulateADCGridView1(result) {
        ADCGridView1.set_dataSource(result);
        ADCGridView1.dataBind();
        alert('onLoadSuccess PopulateADCGridView1 Static fired');
    }
((/script))

The databinding is by reference to the 'ADCGridView1' explicitly. Therefore the controls are named identically when multiple instances of the control are used. Boom! Not work.

So you have to dynamically create the control and add it to the update panel. You then use the controls ID and ClientID to generate the javascript to populate it via the web service of your choice.

I generated the ID of the control by using a random string generator. This was just to make it easy. The code for this is here:
        private string RandomString(int size, bool lowerCase)
        {
            StringBuilder builder = new StringBuilder();
            Random random = new Random();
            char ch;
            for (int i = 0; i < size; i++)
            {
                ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
                builder.Append(ch);
            }
            if (lowerCase)
                return builder.ToString().ToLower();
            return builder.ToString();
        }

Create a property for the Ajax Data Controls ID to be stored in. This will store the Ajax Data Controls GridView ID from the current user control instance.
        //GridView ID to be set for each instance
        private String _ADCGridViewID;
        public String ADCGridViewID {
            get{ return _ADCGridViewID; } 
            set{_ADCGridViewID = value; }
        }

Then inside the PageLoad of the controls code create the control and add them to the Update Panel:
        protected void Page_Load(object sender, EventArgs e)
        {
            this.ADCGridViewID = "ADCGV_"+RandomString(8,true); //String variable

            AjaxDataControls.GridView dGV = new AjaxDataControls.GridView();
            dGV.ID = ADCGridViewID;
            dGV.EnableViewState = true;

            UpdatePanel uDP = this.FindControl("UpdatePanel1") as UpdatePanel;
            uDP.ContentTemplateContainer.Controls.Add(dGV);

}

Then also inside the PageLoad, create the ClientScriptManager to add the javascript required to populate your control and also register 'add_load' event scripts to make them work on load (this was the tricky part).
//Register JavaScript via RegisterStartupScript
            ClientScriptManager csm = Page.ClientScript;

            csm.RegisterStartupScript(this.GetType(), "pageLoad"+ ADCGridViewID,
            @"((script type='text/javascript'))" + System.Environment.NewLine +
            @"function onLoad"+ADCGridViewID+"(result) {" + System.Environment.NewLine +
            ADCGridViewID + @".set_dataSource(result);" + System.Environment.NewLine +
            ADCGridViewID + @".dataBind();" + System.Environment.NewLine +
            //@"alert('onLoad " + ADCGridViewID + " fired');" + System.Environment.NewLine +
            @"}" + System.Environment.NewLine +
            //
            @"function populate"+ADCGridViewID+"() {" + System.Environment.NewLine +
            @"  Cuyahoga.Modules.CatMod.Web.MyWebService.Test_Method(onLoad"+ADCGridViewID+");" + System.Environment.NewLine +
            //@"  alert('function populate" + ADCGridViewID + " fired.');" + System.Environment.NewLine +
            @"}" + System.Environment.NewLine +
            //
            @"Sys.Application.add_load(populate" + ADCGridViewID + ");" + System.Environment.NewLine +
            @"((/script))" + System.Environment.NewLine + System.Environment.NewLine);

This will generate the call to the web service and populate the control based upon the ID and ClientID of the dynamically created Ajax Data Control.

I have added 5 instances of the control to a page and they all populate :)
# juanwoang 4/23/2009 4:26 AM
Hi Constructor (John)
Thank you much, and will try your solutions. You are great.
And I have other solution like share here. My code is simple, but maybe stupid :)

I use a method call PrintOutPageLoad(string pageLoadName, Section s), it mainly answers this question: "Does this section is final one?" and if yes, it will print out pageLoad that call all function "pageLoadName".

I will post it here next time!
# Constructor 4/24/2009 2:33 PM
Updated solution here

With a VERY strange issue that was resolved (but still do not know what it was).
# juanwoang 4/28/2009 5:23 AM
Dear John
My current code is bad. I am trying your solutions. Thanks!
# juanwoang 4/28/2009 5:50 AM
Dear John,
Could you post your sample controls here? I apply your solution but it still not ok. Thanks!
# Constructor 4/28/2009 11:45 AM (edited 4/28/2009 11:57 AM)
juanwoangDear John,
Could you post your sample controls here? I apply your solution but it still not ok. Thanks!

Juan,

I can not post files to forum but here is code that works. I found issues with the above code to but then fixed them here . It was strange as it worked only in debug!

I am using the latest trunk version of the Ajax Data Controls.

There is a much lighter solution that does work well. Note: the < and > are replaced with (( and )):
//GridView ID to be set for each instance
private String _ADCGridViewID;

public String ADCGridViewID {
            get{ return _ADCGridViewID; } 
            set{_ADCGridViewID = value; }
        } 


//Make a random name for each user control Instance so that the JavaScripts can be generated for each instance of the user control.
private string RandomName(int size)
        {
            return System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, size);
        }



protected void Page_Load(object sender, EventArgs e) {   


//Set generated control ID in this User Controls Param
            this.ADCGridViewID = "adc_gv_" + RandomName(8);


AjaxDataControls.GridView dGV = new AjaxDataControls.GridView();
            dGV.ID = ADCGridViewID;
            PlaceHolder uPL = this.FindControl("PlaceHolder1") as PlaceHolder; //Place the created control where you want it.
            uPL.Controls.Add(dGV);


//This adds the relevant JavaScripts (much simpler)
ClientScriptManager csm = Page.ClientScript;
            csm.RegisterStartupScript(this.GetType(), System.Guid.NewGuid().ToString(),
            @"((script type='text/javascript'))//((![CDATA[" + System.Environment.NewLine + 
                @"function onLoad" + ADCGridViewID + "(result) {" + 
                @"var " + ADCGridViewID + @" = $find('" + dGV.ClientID + "');" + 
                    ADCGridViewID + @".set_dataSource(result);" + 
                    ADCGridViewID + @".dataBind();" + 
                @"}" + 
                //
                @"function populate" + ADCGridViewID + "() {" + 
                    @"  Cuyahoga.Modules.CatMod.Web.MyWebService.Test_Method(onLoad" + ADCGridViewID + ");" +
                @"}" + System.Environment.NewLine +
                @"Sys.Application.add_load(populate" + ADCGridViewID + ");" + System.Environment.NewLine + 
            @"//]]))((/script))");

}

This does work, I have tested it thoroughly. Unline the last example that only worked in debug! (and still not sure why).
# Constructor 4/28/2009 10:10 PM (edited 4/28/2009 10:17 PM)
Here is a small test project that uses a very basic web service to send dummy data to the Ajax Data Controls.

It contains a Gridview example and a Repeater.

They both work locally on my machine. Take a look and see if they make things clearer.

I used a modified trunk version to build this (with NHibernate 2), but it should work. You may need to add a reference.