Giter VIP home page Giter VIP logo

tokencontrolreplacer's Introduction

TokenControlReplacer

Class library to take a string input with tokens and replace with LiteralControls and UserControls

Features

  • This utility library allows you to take multiple text strings containg [TOKENS] and replace them with anything that derives from the Control type.
  • Any additional non-token text surrounding your tokens will be converted into a LiteralControl
  • Attributes are also supported for tokens. [BUTTON:Text="Click Me"] will replace the Text property on a button control. Any attribute added that is not a valid property will be added to the controls attribute collection.
  • Token locations are processed only once and are cataloged a preformance benefit on additional replacements.

Instructions

  • Add this project to your solution or simple copy the TokenControlReplacer.cs class into your project.
  • Initialize the class and assign what begin and ends your tokens
var replacer = new TokenControlReplacer("[", "]");
  • Append one or more text blocks to the class
replacer.Append("I am a block of text with a [BUTTON] token.");
  • Identity the token and what you would like to replace it with.
replacer.Replace("[BUTTON]", new Func<Control>(() =>
{
    var buttonCtl = new LinkButton();
    buttonCtl.Click += delegate(object o, EventArgs args) { Response.Redirect("http://inspectorit.com"); };
    buttonCtl.Text = "Go to Website";
    return buttonCtl;
})());
  • Another replacement example
replacer.Replace("[BUTTON]", LoadControl("/PathToControl.ascx"));
  • Add the replaced controls to another control. Recommend a PlaceHolder control
placeHolderOutput.Controls.Add(replacer.Output());

tokencontrolreplacer's People

Contributors

jsheely avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jsheely

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.