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");
}
}
}
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");
}
}
}
Comment