Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StringBuilder .append function outputting escape codes.

Status
Not open for further replies.

tekkerguy

Programmer
Nov 16, 2005
196
0
0
US
I'm trying to append this string, to a onclick function:

Code:
                    popupFunction.Append("','");
                    popupFunction.Append("'<%serRowList.ClientID%>.value'");
                    popupFunction.Append(")");


All other codes work, but this one, when rendered into the page, keeps changing the < sign to &lt; escape sequence.

How do I prevent this?
 
yes, this is expected as it's a prevetative measure against XSS.

your trying to use a server object and client tags. what excatly are you trying to do? if it's bulding out a js statment. either
Code:
<script lang="javascript">
   function foo()
   {
      alert('<%serRowList.ClientID%>');
   }
</script>
or
Code:
protected void OnLoad(EventArgs e)
{
   if (!this.IsPostBack)
   {
      StringBuilder builder = new StringBuilder();
      builder.FormatAppend("function foo(){alert('{0}');}", serRowList.ClientID);
      ClientScriptManager.RegisterScript("foo", this.GetType(), builder.ToString(), true);
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I am loading a composite page which holds other controls.

I am trying to append an onclick function to a button in one of the contained controls from a separate inherited class.

I have to use this because the hidden control is a serverside object and is appending ctl01_ ... to the control.

The separate inherited class cannot see the control directly, hence why I'm creating a string and appending to the onclick event of the button.

It's difficult to explain, but this is the way I have to do it, but I can't stop it from changing the < to &lt;

 
ok, you'll need to define the databound event for the row/item. find the control and use conrols.attributes.add to add the js call. something like this
Code:
void RepeaterItem_DataBound(...)
{
   if(e.Item.ItemType == ItemType.DataItem)
   {
      Button b = (Button)e.Item.FindControl("mybutton");
      b.Attributes.Add("onclick", "alert('foo');");
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top