Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. The difference between <%=var%> and <%#var#>

The difference between <%=var%> and <%#var#>

Scheduled Pinned Locked Moved ASP.NET
questioncsharptoolshelptutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stonie
    wrote on last edited by
    #1

    Hello everyone, I was hoping someone could give me an answer or a link to a good article of the difference between using data binders for simple properties and using response.write for simple properties in aspx pages. Some context to my question: I have some webforms that contain of various types. At run time if a control contains a particular value, I modify the controls collection and add a div around the control. Like this: public static void AddErrorContainer(Control control) { HtmlGenericControl errorDiv = new HtmlGenericControl("div"); errorDiv.Attributes.Add("class", "errorBox"); control.Parent.Controls.AddAt(control.Parent.Controls.IndexOf(control)+1, errorDiv); control.Parent.Controls.Remove(control); errorDiv.Controls.Add(control); } However if the control that I am trying to add the div to contains an script blocks for example: <%=var%> a runtime error is thrown. “Cannot modify the controls collection when script blocks are present” However if I switch to data binders IE: <%#var%> and call this.DataBind() in the page_load() then everything is fine? My question then is: What is the difference between the two methods? I realise that the response.write method writes to the output stream? And databinder is invoked when DataBind is called? But… what is the difference internally? Why is it not possible to modify the controls collection when script blocks are present? I have been having trouble finding any good documentation on this, if anyone could give me an answer or a URL, that would be great. Thanks in advance. :-D Kind regards, Andrew. Andrew Stone. http://andrewstone.net

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups