Saturday, March 24, 2012

text placing directly?

hi guys,

I would like to have my web user control take a piece of text directly from it's calling tag,eg:

<UserControl:Search id="Search" runat="server" SomeText="Text"></UserControl:Search
And have it render this text in it's .ascx file. The .cs file I have looks something like this:

namespace Searching
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

protected string sometext;

public class Search : System.Web.UI.UserControl
{
public string SomeText
{
get { return sometext; }
set { sometext = value; }
}

private void Page_Load(object sender, System.EventArgs e)
{
}
}
}

My question is: How do I get just a plain string to render directly to, for example:

the HERE part?

The actual application of this code is to pass by tag argument the url of a single image and have it render as part of the ascx output.

Thanks,
Matt.Try this:

<%@. Control Language="C#" %>
<script runat="server"
protected string sometext;

public string SomeText
{
get { return sometext; }
set { sometext = value; }
}

private void Page_Load(object sender, System.EventArgs e)
{
thisLink.Attributes.Add( "href", SomeText + ".aspx" );
thisLink.InnerHtml = "goto " + SomeText + " page";
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<a id="thisLink" runat="server"></a>
</form>
</body>
</html>

(I don't actually use C#, so the code might be of poor quality ...)

0 comments:

Post a Comment