data binding problem

L

Lloyd Dupont

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.Diagnostics;

using System.Drawing;

using System.Drawing.Imaging;

using System.IO;

using System.Text;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

namespace perso

{

/// <summary>

/// Summary description for WebCustomControl1.

/// </summary>

[DefaultProperty("Filename"),

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

public class WebPreviewer : Control

{

private string text = @"?";

[Bindable(true), Category("Appearance"), DefaultValue("")]

public string Filename

{

get

{

return text;

}

set

{

text = value;

}

}

int size;

[Bindable(true), Category("Appearance"), DefaultValue("50")]

public int Size

{

get

{

if(size < 1)

return 50;

return size;

}

set

{

size = value;

}

}

protected override void OnPreRender(System.EventArgs e)

{

StringBuilder script = new StringBuilder();

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

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

script.Append("\targs =
\"statuts,scrollbars,location,resizable,width=\"+aW+\",height=\"+aH;\n");

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

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

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

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

Page.RegisterClientScriptBlock("__stuff_view",script.ToString());

base.OnPreRender(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(HtmlTextWriter output)

{

string myurl = Page.ResolveUrl(Filename);

myurl = HttpUtility.UrlEncode(myurl);

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

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

output.Write(Size);

output.Write("&url=");

output.Write(myurl);

output.Write('\'');

output.Write(" onclick=\"return ");

output.Write("__stuff_view('awin','");

output.Write(myurl);

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

output.Write('\"');

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

}

}

}
 
L

Lloyd Dupont

my property Filename is set as follow
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Name")>
<asplloyd:WebPreviewer runat=server
Filename='<%# DataBinder.Eval(Container.DataItem, "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 said:
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.Diagnostics;

using System.Drawing;

using System.Drawing.Imaging;

using System.IO;

using System.Text;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

namespace perso

{

/// <summary>

/// Summary description for WebCustomControl1.

/// </summary>

[DefaultProperty("Filename"),

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

public class WebPreviewer : Control

{

private string text = @"?";

[Bindable(true), Category("Appearance"), DefaultValue("")]

public string Filename

{

get

{

return text;

}

set

{

text = value;

}

}

int size;

[Bindable(true), Category("Appearance"), DefaultValue("50")]

public int Size

{

get

{

if(size < 1)

return 50;

return size;

}

set

{

size = value;

}

}

protected override void OnPreRender(System.EventArgs e)

{

StringBuilder script = new StringBuilder();

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

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

script.Append("\targs =
\"statuts,scrollbars,location,resizable,width=\"+aW+\",height=\"+aH;\n");

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

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

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

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

Page.RegisterClientScriptBlock("__stuff_view",script.ToString());

base.OnPreRender(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(HtmlTextWriter output)

{

string myurl = Page.ResolveUrl(Filename);

myurl = HttpUtility.UrlEncode(myurl);

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

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

output.Write(Size);

output.Write("&url=");

output.Write(myurl);

output.Write('\'');

output.Write(" onclick=\"return ");

output.Write("__stuff_view('awin','");

output.Write(myurl);

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

output.Write('\"');

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

}

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top