data binding problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lloyd Dupont

    #1

    data binding problem

    I have developped a custom user control (code at the end of the mail) which
    is an <input> tag with a customized source and onclick method.
    This custom control is in a repeater (in a template column of a datagrid, in
    fact), when the user clicked it and the web form is updated its Filename
    property has a now incorrect calue.

    however when I click on another input element (for example I click on the
    sort link at the top of the table) everything is then displayed correctly.

    I'm puzzled, any tip ?

    (Note: the Filename property is <%# databounded %>, of course !)

    //--------- WebPreviewer.cs -------
    using System;

    using System.Diagnost ics;

    using System.Drawing;

    using System.Drawing. Imaging;

    using System.IO;

    using System.Text;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.W ebControls;

    using System.Componen tModel;

    namespace perso

    {

    /// <summary>

    /// Summary description for WebCustomContro l1.

    /// </summary>

    [DefaultProperty ("Filename") ,

    ToolboxData("<{ 0}:WebPreviewer runat=server></{0}:WebPreviewe r>")]

    public class WebPreviewer : Control

    {

    private string text = @"?";

    [Bindable(true), Category("Appea rance"), DefaultValue("" )]

    public string Filename

    {

    get

    {

    return text;

    }

    set

    {

    text = value;

    }

    }

    int size;

    [Bindable(true), Category("Appea rance"), DefaultValue("5 0")]

    public int Size

    {

    get

    {

    if(size < 1)

    return 50;

    return size;

    }

    set

    {

    size = value;

    }

    }

    protected override void OnPreRender(Sys tem.EventArgs e)

    {

    StringBuilder script = new StringBuilder() ;

    script.Append(" <script language='javas cript'><!--\n");

    script.Append(" function __stuff_view(id ,file,aW,aH){\n ");

    script.Append(" \targs =
    \"statuts,scrol lbars,location, resizable,width =\"+aW+\",heigh t=\"+aH;\n");

    script.Append(" \topen(file, id, args);\n");

    script.Append(" \treturn true;\n");

    //script.Append(" \treturn false;\n");

    script.Append(" }\n//--></script>");

    Page.RegisterCl ientScriptBlock ("__stuff_view" ,script.ToStrin g());

    base.OnPreRende r(e);

    }



    /// <summary>

    /// Render this control to the output parameter specified.

    /// </summary>

    /// <param name="output"> The HTML writer to write out to </param>

    protected override void Render(HtmlText Writer output)

    {

    string myurl = Page.ResolveUrl (Filename);

    myurl = HttpUtility.Url Encode(myurl);

    output.Write("< input type=image");

    output.Write(" src='Previewer. aspx?size=");

    output.Write(Si ze);

    output.Write("& url=");

    output.Write(my url);

    output.Write('\ '');

    output.Write(" onclick=\"retur n ");

    output.Write("_ _stuff_view('aw in','");

    output.Write(my url);

    output.Write("' ,'500','500')") ;

    output.Write('\ "');

    output.Write("/>\n");

    }

    }

    }


  • Lloyd Dupont

    #2
    Re: data binding problem

    my property Filename is set as follow
    <ItemTemplate >
    <%# DataBinder.Eval (Container.Data Item, "Name")>
    <asplloyd:WebPr eviewer runat=server
    Filename='<%# DataBinder.Eval (Container.Data Item, "Name")>'/>
    </ItemTemplate>

    so I display the theoric value of filename which is correct.
    but for some reason the Filename property is not set ...


    "Lloyd Dupont" <lloyd@RemoveIf NotSpamming.gal ador.net> a écrit dans le
    message de news:un%23%23rs GTDHA.3192@tk2m sftngp13.phx.gb l...[color=blue]
    > I have developped a custom user control (code at the end of the mail)[/color]
    which[color=blue]
    > is an <input> tag with a customized source and onclick method.
    > This custom control is in a repeater (in a template column of a datagrid,[/color]
    in[color=blue]
    > fact), when the user clicked it and the web form is updated its Filename
    > property has a now incorrect calue.
    >
    > however when I click on another input element (for example I click on the
    > sort link at the top of the table) everything is then displayed correctly.
    >
    > I'm puzzled, any tip ?
    >
    > (Note: the Filename property is <%# databounded %>, of course !)
    >
    > //--------- WebPreviewer.cs -------
    > using System;
    >
    > using System.Diagnost ics;
    >
    > using System.Drawing;
    >
    > using System.Drawing. Imaging;
    >
    > using System.IO;
    >
    > using System.Text;
    >
    > using System.Web;
    >
    > using System.Web.UI;
    >
    > using System.Web.UI.W ebControls;
    >
    > using System.Componen tModel;
    >
    > namespace perso
    >
    > {
    >
    > /// <summary>
    >
    > /// Summary description for WebCustomContro l1.
    >
    > /// </summary>
    >
    > [DefaultProperty ("Filename") ,
    >
    > ToolboxData("<{ 0}:WebPreviewer runat=server></{0}:WebPreviewe r>")]
    >
    > public class WebPreviewer : Control
    >
    > {
    >
    > private string text = @"?";
    >
    > [Bindable(true), Category("Appea rance"), DefaultValue("" )]
    >
    > public string Filename
    >
    > {
    >
    > get
    >
    > {
    >
    > return text;
    >
    > }
    >
    > set
    >
    > {
    >
    > text = value;
    >
    > }
    >
    > }
    >
    > int size;
    >
    > [Bindable(true), Category("Appea rance"), DefaultValue("5 0")]
    >
    > public int Size
    >
    > {
    >
    > get
    >
    > {
    >
    > if(size < 1)
    >
    > return 50;
    >
    > return size;
    >
    > }
    >
    > set
    >
    > {
    >
    > size = value;
    >
    > }
    >
    > }
    >
    > protected override void OnPreRender(Sys tem.EventArgs e)
    >
    > {
    >
    > StringBuilder script = new StringBuilder() ;
    >
    > script.Append(" <script language='javas cript'><!--\n");
    >
    > script.Append(" function __stuff_view(id ,file,aW,aH){\n ");
    >
    > script.Append(" \targs =
    > \"statuts,scrol lbars,location, resizable,width =\"+aW+\",heigh t=\"+aH;\n");
    >
    > script.Append(" \topen(file, id, args);\n");
    >
    > script.Append(" \treturn true;\n");
    >
    > //script.Append(" \treturn false;\n");
    >
    > script.Append(" }\n//--></script>");
    >
    > Page.RegisterCl ientScriptBlock ("__stuff_view" ,script.ToStrin g());
    >
    > base.OnPreRende r(e);
    >
    > }
    >
    >
    >
    > /// <summary>
    >
    > /// Render this control to the output parameter specified.
    >
    > /// </summary>
    >
    > /// <param name="output"> The HTML writer to write out to </param>
    >
    > protected override void Render(HtmlText Writer output)
    >
    > {
    >
    > string myurl = Page.ResolveUrl (Filename);
    >
    > myurl = HttpUtility.Url Encode(myurl);
    >
    > output.Write("< input type=image");
    >
    > output.Write(" src='Previewer. aspx?size=");
    >
    > output.Write(Si ze);
    >
    > output.Write("& url=");
    >
    > output.Write(my url);
    >
    > output.Write('\ '');
    >
    > output.Write(" onclick=\"retur n ");
    >
    > output.Write("_ _stuff_view('aw in','");
    >
    > output.Write(my url);
    >
    > output.Write("' ,'500','500')") ;
    >
    > output.Write('\ "');
    >
    > output.Write("/>\n");
    >
    > }
    >
    > }
    >
    > }
    >
    >[/color]


    Comment

    Working...