Showing posts with label autoeventwireup. Show all posts
Showing posts with label autoeventwireup. Show all posts

Wednesday, March 28, 2012

extenders arent working at all

Hi. I have installed libarary and control toolkit, and I have the following code:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TaskCenter.WebForm1" EnableEventValidation="true" %><%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %><%@dotnet.itags.org. Register Assembly="Microsoft.Web.Extensions" Namespace="Microsoft.Web.UI" TagPrefix="aj" %><%@dotnet.itags.org. Register Assembly="Microsoft.Web.Extensions" Namespace="Microsoft.Web.UI.Controls" TagPrefix="aj" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <aj:ScriptManager ID="sm" EnablePartialRendering="True" runat="Server" /> <asp:Label ID="test" runat="Server">test</asp:Label> <asp:Panel ID="panel1" runat="server" Enabled="true">testtttt</asp:Panel><ajax:DropDownExtender runat="server" ID="DDE" TargetControlID="test" DropDownControlID="panel1" OnResolveControlID="DDE_ResolveControlID" /> </div> </form></body></html>

Problem is, it doesn't work. The app builds without any problem, and when I open the page i see two text labels - test and testtt, no extender, no dropdown.

How do I fix it?

Look in the web.config for the SampleWebsite. Make sure you have the sections under httpHandlers and httpModules in your web.config.

extender control inside databound controls

I will show you a piece of code that worked with the last CTP:

<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="test.aspx.cs"Inherits="test" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<headrunat="server">

<title>Databound Controls</title>

</head>

<body>

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

<atlas:ScriptManagerEnablePartialRendering=trueID="sm"runat="server"></atlas:ScriptManager>

<

asp:RepeaterID="rpt"runat="server"DataSourceID="xmlData"OnItemDataBound="rpt_ItemDataBound">

<ItemTemplate>

<%# XPath("name") %><asp:TextBoxID="textInside"runat="server"></asp:TextBox><br/>

<atlastoolkit:TextBoxWatermarkExtenderID="watInside"TargetControlID="textInside"runat="server"WatermarkText="Inside TextBox"/>

</ItemTemplate>

</asp:Repeater>

Somebody<asp:TextBoxID="textOutside"runat="server"></asp:TextBox><br/>

<atlastoolkit:TextBoxWatermarkExtenderID="watOutside"runat="server"TargetControlID="textOutside"WatermarkText="Outside TextBox"/>

<asp:XmlDataSourceID="xmlData"runat="server"XPath="contacts">

<Data>

<contacts>

<name>Peter</name>

</contacts></Data>

</asp:XmlDataSource>

</form>

</body>

</html>

This piece of code is not working anymore more. The responsible is the “new” behaviour of the TargetControlID. Now, you need the ClientID of the target control, not the usual control ID.

In the easy case, both (ClientID and ID) are the same, but not inside databound controls. So what you need now is:

First, you need to DataBind() the Page at load stage; this is because you need the extender controls in the control tree before the (Pre)Render stage; otherwise, they won’t render.

Second, you need to delete the TextBoxWatermarkExtender instantiated declaratively, and add it at runtime:

protectedvoid rpt_ItemDataBound(object sender,RepeaterItemEventArgs e)

{

AjaxControlToolkit.TextBoxWatermarkExtender tbe =new AjaxControlToolkit.TextBoxWatermarkExtender ();

tbe.TargetControlID = (e.Item.FindControl("textInside")asTextBox).ClientID;

tbe.ID ="watInside";

tbe.WatermarkText ="Inside Text";

tbe.ResolveControlID +=new AjaxControlToolkit.ResolveControlEventHandler(tbe_ResolveControlID);

e.Item.Controls.Add(tbe);

}

Finally, the extender control is not still able to find the TargetControlID, so you have to make up your own FindControl (like this one) :

void tbe_ResolveControlID(object sender, AjaxControlToolkit.ResolveControlEventArgs e)

{

e.Control =Util.FindControl(e.ControlID,"_",this.Page);

}

publicstatic System.Web.UI.Control Util.FindControl(string cliendid,string separator, System.Web.UI.Control root)

{

int i = 0;

string[] sepControls = cliendid.Split(separator[0]);

System.Web.UI.Control fc =null;

for (fc = root; (null != fc) && i < sepControls.Length; i++)

{

fc = fc.FindControl(sepControls[i]);

}

if (fc !=null && fc.ClientID == cliendid)return fc;

elsereturnnull;

}

If someone knows any other way to simplify this case, please tell me. Otherwise, my project has become a nightmare.

fran

Your original sample works fine for me with the addition of only:

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
rpt.DataBind();
}

More details here:http://forums.asp.net/thread/1441672.aspx.