Hello everybody,
Please tell me if this is not the good forum, I have difficulties to authorize client script in a user component when it is displayed on a DataList.
To be more precise, I wrote a user component to display the details of a dish for a restaurant, and select a few options about it. This includes a Slider control from the Ajax Control Toolkit, to select the cooking level (would you prefer to say cooking grade ?), for dishes for which the cooking is managed that way, rather than light, medium, well cooked. There are also two imagebuttons, to increase or decrease the value of it of 10.
All that runs pretty good when the component is shown independently on the page, but as the aim is to allow the final customer to select a dish, of course I have to display that component in several copies on the page. So I inserted it in the ItemTemplate of a DataList.
Since I did that, the Slider runs once, and at the second attempt to modify its value, a messagebox is displayed like this :
When seeing that, I inserted this in the code page, to allow the first imagebutton :
protected override void Render(HtmlTextWriter writer) { ClientScriptManager cs = Page.ClientScript; UserControls_AffichePlat ap = (UserControls_AffichePlat)DataList1.Controls[0].FindControl("AffichePlat1"); ImageButton imb = (ImageButton)ap.FindControl("imgGauche10"); string strId = imb.ClientID; string strCC = imb.OnClientClick; cs.RegisterForEventValidation(strId, strCC); base.Render(writer); }
strId and strCC looked as I planed, and a breakpoint allowed me to verify that this code is executed.
But, the imagebutton still launches the same messagebox instead of executing the client script I wrote.
Here is a copy of the beginning of the code page :
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" Trace="false" CodeFile="Viandes.aspx.cs" Inherits="Viandes" Title="Viandes" Culture="auto" meta:resourcekey="PageResource1" UICulture="auto" EnableEventValidation="true" %><%@ Register Src="UserControls/AffichePlat.ascx" TagName="AffichePlat" TagPrefix="uc1" %>
So you see that I placed EnableEventValidation at the end of the Page element.
Any idea what to do ?
Perhaps one more precision : for the moment being, the DataList displays one record. I shall do tests with several records (several dishes) once the test is OK with one.