Sunday, March 11, 2012

Error: Sys.ArgumentException: Value must not be null for Controls and Behaviors. Ajax vs A

Hi,

There was a bug in the beta where extenders and script controls do not work inside databound controls such as the GridView. This issue will be fixed in our next release.

Thanks,

Eilon


When is the next release?

There was a supposed "work around" posted where you simply called GridView1.DataBind() in the PageLoad event.

While this workaround did fix the problem in a simple test page I threw together, it did not fix the problem in the "real" page on our website where we were trying to use an extender in a row in a GridView.

Both my "test" example use a GridView with a templated column containing a ToggleExtender on a checkbox. The only difference I can see between my test page and the "real" page is that the "real" page is a lot more complicated (more columns, more content in the template column, sits inside a WebControl inside a page that uses a MasterPage, etc...)

The "test" example was just a stand alone webpage with no MasterPages or Web Controls being used. I'd love to roll out this Ajax functionality in our next deployment, but issues like this prevent me...


Just for your info:

I have the same problem when I use extenders in Wizard control. As soon as I navigate from WizardStep where extenders are I'm getting the error. It looks like it happens every time when extender is in the invisible conrol. And it is true that it occurs only in AJAX not in ATLAS.

Regards


I had the same problem, and got around it by inserting the extender it in the code behind instead of on the page. Not too much of a hassle, fortunately.

My code looked something like this, might be something to help you get going... note that I have a set number of cells.

Protected Sub TheGridView_RowDataBound( _
ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles TheGridView.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(4).FindControl("controlTarget").Visible = True
e.Row.Cells(4).FindControl("controlPopup").Visible = True
Dim hmx As New AjaxControlToolkit.HoverMenuExtender
With hmx
.TargetControlID = e.Row.Cells(4).FindControl("controlTarget").UniqueID
.PopupControlID = e.Row.Cells(4).FindControl("controlPopup").UniqueID
End With
End If

End Sub


I'm having the same problem with AutoCompleteExtender inside a Wizard control, which in turn is inside an UpdatePanel. When the textbox and the extender are on the first page of the wizard they work fine. If I move them to say the third page I'm getting this error:

Sys.ArgumentException: Value must not be null for Controls and Behaviors

I tried absolutely everything - adding the extender in code-behind, accessing the Controls collection, etc. etc. Looks like when the extender is on an invisible Wizard step this error occurs.

Lupi


Lupi:

I tried absolutely everything - adding the extender in code-behind, accessing the Controls collection, etc. etc. Looks like when the extender is on an invisible Wizard step this error occurs.

I haven't used the wizard, but isn't it possible in the code-behind to create an extender only for the Wizard step you are currently showing? I would imagine this is similar to the problem with the gridview - you have to create the extender there for only the rows/cells that are currently showing.


Omg fawtry, why didn't I think about that myself. I added some code in the ActiveStepChanged event handler, which checks for ActiveStepIndex of the wizard control and eventually adds a dynamic AutoCompleteExtender to the Controls collection of the needed wizard step. Here is some code, which is trivial:

protected void wizardApplication_ActiveStepChanged(object sender, EventArgs e)
{
if (wizardApplication.ActiveStepIndex == 2)
{
AutoCompleteExtender extender = new AutoCompleteExtender();
extender.ID = "txtCityExtender";
extender.TargetControlID = "txtCity";
extender.CompletionInterval = 1;
extender.MinimumPrefixLength = 4;
extender.ServiceMethod = "GetCitiesWithNameLike";
extender.ServicePath = "~/ProxyService.asmx";

wizardApplication.WizardSteps[2].Controls.Add(extender);
}
}

This works like charm for a wizard inside an UpdatePanel.


I'm glad you got it to work... I was a little too quick above to assume that since it worked on the first page of the gridview, it would work after I navigated to another page... not so. :D

It seems that even though it goes through the exact same binding code for each gridview page, it just doesn't render the control right. There are no error messages, just no hover-functionality - the popup control shows based on visibility property and nothing else. It seems like the hovercontrol simply doesn't do anything.

I haven't found any way to get around this... anyone else have any ideas?


It might have something to do with any commented-out code in your aspx (or, in my case ascx) file.

e.g. <!-- <asp:UpdatePanel ID="CognosUpdatePanel" runat="server">
<ContentTemplate> -->

Now, even though it's commented out, ASP.NET still seems to do things with it.

The way I found to get it to ignore it (other than deleting all the code as I want to use it in future) is to disguise the runat attribute. i.e.

<!-- <asp:UpdatePanel ID="CognosUpdatePanel" Xrunat="server">
<ContentTemplate> -->

Nick


(doonhamer) great solution, it fixed my issue


try using the ID instead of UniqueID as well.

eg.
.TargetControlID = e.Row.Cells(4).FindControl("controlTarget").ID
.PopupControlID = e.Row.Cells(4).FindControl("controlPopup").ID

that seemed to help when i was using the calendarextender in a server control

No comments:

Post a Comment