Generating Clean Markup With Literal And String.Format

Jun 2, 2010

In order to generate clean markup, I often resort to using code similar to this:

<asp:Literal ID="ltItem" runat="server">
<li class="{0}"><a href="{1}">{2}</a></li></asp:Literal>

And in the codebehind:

[code]....

Therefore my question:

Is this a common way to generate clean markup? Are there better alternatives? Is the databinding syntax approach preferable?

View 1 Replies


Similar Messages:

Web Forms :: Custom Format String In Markup?

May 18, 2010

Is it possible to use a custom format string in the markup? In the codebehind page the string looks like this:

MyBoundField.DataFormatString = "{0:n" + MyEnvironment.CurrentCulture.NumberFormat.CurrencyDecimalDigits + "}";

i.e i want to do something like the below example (but that does not work)

<
asp:BoundField
DataField="Amount"
DataFormatString="{0:n'<%# SummarumEnvironment.CurrentCulture.NumberFormat.CurrencyDecimalDigits.ToString())
%>'"
/>

View 1 Replies

Javascript - String Having <br/> Throws Unterminated String Literal Js Error

Jan 28, 2011

I am fetching some data from Db and displaying it in a textarea using jquery in the following way.$('#textareatest').val('<% =teststring %>').It is possible that the string 'teststring' can contain XHTML line breaks(<br/>).whenever the string contains <br/> I am getting the 'unterminated string literal' error.I saw a number of posts considering '' as line breaks and suggesting to escape it.I tried to escape the <br/> similarly,but it didn't work.

View 4 Replies

Generating Control Markup Based On A Dynamically Generated Control?

Dec 9, 2010

What I'm trying to do is take an instance of a control, and figure out what the markup would look like based on the property values set in the code behind. We've built a web-based web form designer. At the end of the design process we save the markup. For simple controls with supported types, generating the markup was easy. For complex controls with nested properties or unsupported types, we're faced with creating a custom markup generator for each custom control. I was hoping to find info out there that would jump start this development effort.

In simple terms, I have this:

Dim Ctl as Control = CType(Asm.CreateInstance("MyNameSpace.MyControl"), Control)
Ctl.Name = "Name of my control"

And I want to end up with this:

<cc1:MyControl ID="MyControl1" runat="server" Name="Name of my control" />

View 1 Replies

C# - Generating A Literal For Each Item In An Item Collection?

Oct 21, 2010

As it stands right now, I have a literal control on my page. In my code-behind, I'm using StringBuilder to generate some JavaScript. Also on that page I have a item collection. What I want to do is for each item in my item collection, generate my literal which will in essence generate my JavaScript. Here is an example of my code-behind now. I'm ok with doing something different, but I just need to generate said JavaScript for every item in the collection and I'm not sure how to do it.

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type='text/javascript'>");
sb.Append("mboxCreate("product_productpage_rec",");
sb.Append(""entity.id=" + _prodID + "",");
sb.Append(""entity.categoryId=" + _categoryID + "",");
sb.Append(""entity.name=" + _prod.Title + "",");
sb.Append(""entity.pageURL=" + Request.Url.ToString() + "",");
//The following value has been taken from the productImageControl code behind.
//Might have to refactor in future as a property of the image control.
string filename = AppSettingsManager.Current.ProductImagePathLarge + _prod.ActiveProductItemCollection[0].Sku + AppSettingsManager.Current.ProductImageExtension;
sb.Append(""entity.thumbnailURL=" + filename + "",");
sb.Append(""entity.inventory=" + _prod.ActiveProductItemCollection.Count + "",");
sb.Append(""entity.value=" + _prod.ActiveProductItemCollection[0].ActualPrice + "",");
sb.Append(""entity.ProductItemID=" + prodItem.Id + "",");
sb.Append(""entity.addToCartImg=~/Images/Buttons/btn_AddToCartFlat.gif");<");
//The last line has to be /script. < inserted on prev line. do not change it or bad things will happen.
sb.Append("/script>");
//add script to page
this.LiteralMBoxScript.Text = sb.ToString();

View 4 Replies

C# - How To Make Sure A String Is Clean For Insertion Into Javascript Alert('error Message')

Jun 24, 2010

I am trying to display an error to the user of a web page using a javascript alert popup, I currently have the following code to clean the error string:

errorMessage.Replace("'", "'")

But this is not sufficient as some illegal characters are not being removed, is there a static method somewhere in the framework that will format my string for clean insertion into html?Update: my initial question was slightly ambiguous. the string needs to be valid as in alert('this is some 'illegal text' that will not popup');I will try Server.HtmlEncode, hopefully it will do the trick.

View 7 Replies

C# - Using String.Format To Build Regular Expressions: "Input String Was Not In A Correct Format"

Mar 7, 2011

I'm bulding document-from-template engine. At certain points I need to match on Reg Exp groups and replace template text with content from a db.

I 'hardcoded' my RegExp initially, doing something like: Regex r = new Regex(@"{DocSectionToggle::(?<ColumnName>w+)::(?<ResponseValue>.+)}[[(?<SectionContent>.+)]]", RegexOptions.Multiline);

it does group capture, so the syntax isn't the prettiest.

Just to make things neater and because I want' to keep the patterns in web.config or elsewhere, I've 'evolved' algorithm to something like:

[code]...

But I'm getting an error: 'Input string was not in correct format'.

Is this a limitation of string.Format(...)?

View 2 Replies

Forms Data Controls :: Data Format Strings To Clean It Up?

Feb 17, 2011

I have a decimal value that is a winning percentage so will always be three digits to the right of the decimal but I dont want the 0 appearing to the left of the decimal.What format string can I use to clean it up?

I want .667

im getting 0.667

View 1 Replies

Web Forms :: Using A Literal/Label Vs. Protected String

Sep 30, 2010

Can someone please tell me the difference and the advantages in these other than styling them? ```First option:

[Code]....
[Code]....

View 3 Replies

C# - Container.DataItem Being Passed As A String Literal?

Aug 16, 2010

I'm trying to pass a string value to a javascript function from a LinkButton's OnClientClick event, but the function is receiving "<%# Container.DataItem %>" instead of the value. Here's the code:

OnClientClick="javascript:SaveQuotaGroupCode('<%# Container.DataItem %>');"

The container is a collection of strings. Why is it not evaluating?EDIT: This is located in a nested ListView. The datasource for the inner ListView is a property in the datasource of the outer ListView.

View 1 Replies

Getting 'too Many Characters In String Literal' In The First Line Of Function?

Nov 25, 2010

Here is my JavaScript:

<script type="text/javascript">
function onholdev(index) {
var chk = document.getElementById('<%=grdCons.Rows[' + index + '].FindControl

[code]...

View 3 Replies

ASP Literal Or Page Altering HTML String Causes Formatting

Jun 16, 2010

We have a service that generates a report (using word templates and a 3rd party library), and then returns a string in HTML. While this HTML isn't great - its formatted correctly in this string. We want this HTML to show up on a page - format intact. What we currently have done is set an ASP.net Literal's text element to this string. While this works, I have noticed that it has reformatted the HTML string slightly. For the most part, it looks like it generated a bunch of new CSS classes, and a new style element in the HTML. This HTML does not exist in the string thats being returned. I could filter all of this back out, but wonder if there is a better way. I assume that the Page itself is altering something. What is the best way to display this raw HTML back to the user? I can't directly use a Response.Write(string), because this page does have a few other controls on it.

View 3 Replies

SQL Server :: How To Build Long Query String Error / Too Many Characters In Character Literal

Sep 23, 2010

I know that it is basic questions, but I am stuck here.

I have TableOne have fields: USERNAME, PID, GID, TID, SID, NEWSID. I need to write query string to check if those value is already in the table. If not, insert those value to the table.

[code]....

However, I got the many errors:

Error 1 Too many characters in character literal

Error 3 Newline in constant

View 3 Replies

C# - Format Exception - Input String Was Not In A Correct Format

Oct 18, 2010

[code]....

Isn't this how u convert string to int ?

int.Parse(e.CommandArgument.ToString());

Whats wrong ?

View 3 Replies

Generating Output On Query String

Jan 17, 2011

I have an ASP.NET website in which I have to perform a certain operation. I have to displaying the ID's from the DB on menu.aspx page in this format {1:2:3:4}. The above format is not a problem and can be just be written with

[code]....

Note that I am saying that user will type this URL. I know that query string can pass the values from one form to another but this is a single web form and if I attach this ?search=yes, it should return the result. How can this be done?

View 2 Replies

Generating Output Through Query String In The Same Page

Jan 17, 2011

I have an ASP.NET website in which I have to perform a certain operation. I have to displaying the ID's from the DB on menu.aspx page in this format {1:2:3:4}. The above format is not a problem and can be just be written with

[Code]....

But here comes my question. I have to generate this ID when the user types the query within the URL somewhat like

[Code]....

Note that I am saying that user will type this URL. I know that query string can pass the values from one form to another but this is a single web form and if I attach this [Code].... , it should return the result. How can this be done?

View 3 Replies

Web Forms :: Generating String / Why Data Is Doubling

Mar 2, 2010

I have a simple function that is supposed to create a string of year values(separated by a comma) from a form that contains checkboxes for a set of years.

[Code]....

The problem is, it is doubling data somehow. For example, if I check the checkboxes for 2008, 2009, 2010, it will return :

,2010,2010,2009,2010,2009,2008

But I can't figure out why it is doing this...is there something I am doing wrong?

View 3 Replies

Web Forms :: UserControl With DateTime Property - Set Markup In Local Datetime Format

Jan 21, 2010

I created a UserControl and added a public DateTime property. I want to set this property in Markup (ie. <cc1:MyControl runat="server" id="MyControl1" DateTimeProp="1/1/2010" /> ) however I live in a place with a dd/mm/yyyy date format so it complains if I set something like "20/1/2010". Is there a way to set markup in my local datetime format or do I have to conform to "mm/dd/yyyy"?

View 2 Replies

C# - DataContractJsonSerializer Generating Ghost String To JSON Keys?

May 21, 2010

DataContractJsonSerializer this is nice class added in the .net framework which can be used to serialize/desirealize object into JSON.

Now following is the example i am trying

[Serializable] class User { public string name; public string userId; }

Now following is the output generated

Output : Notice structure where only "name" is expected instead of k__BackingField

Now this is the problem after digging so much i am not sure from where <> and _BackingField is coming ?

{
"<name>k__BackingField":"test user",
"<userId>k__BackingField":100001}

View 1 Replies

Forms Data Controls :: Change The Date Format From String To String At Gridview?

Feb 24, 2011

i facing a problem to change the date format at gridview display.

below is my coding:

[code]....

View 2 Replies

DataSource Controls :: Incorrect String / Format The QueryBuilder String Correctly In Code?

Jul 7, 2010

I'm concatenating a string in codebehind to use in a sql select statement.

in aspx

<asp:Label ID="LabelHidden" runat="server" Visible="False"></asp:Label>
SelectCommand="SELECT * FROM [Data] WHERE [ActivityName] IN (@ActivityName) AND ([ID] = @ID)"
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList_Employees" Name="ID"
PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter ControlID="LabelHidden" Name="ActivityName"
Type="String" />
</SelectParameters>
in codebehind
foreach (ListItem li in ListBox_Activities.Items)
{
if (li.Selected)
{
queryBuilder += li + "', ";
}
queryBuilder = queryBuilder.Substring(0, queryBuilder.Length - 1);
LabelHidden.Text = queryBuilder;

When i run the code it comes up blank. I did a query trace and it seems to be running as

exec sp_executesql N'SELECT * FROM [Data] WHERE [ActivityName] IN (@ActivityName) AND ([ID] = @ID)',N'@EmployeeID int,@ActivityName nvarchar(50)',@EmployeeID=4,@ActivityName=N'Production Technical Support'', Tools Development'','

with exta "'s

How can i format the queryBuilder string correctly in my code?

View 3 Replies

VS Macro / Add-in To Convert String Concatenations To String.format Style

Jul 28, 2010

I have project in development where string operations like "Hi " + variable + ", welcome to Project" are used at many places (given example is very minor one).

One of the requirement is to convert it to string.format style.

It is very long and tedious job, where I would not like to break earlier working code due to any human error might happen while converting it.

I would like to if any Macro or VS command which I can create to handle it. Just like we mark block of code and do Extract function in Re-factor options.

View 1 Replies

JavaScript - Format A String Using A String Pattern?

Sep 23, 2010

I have a displayFormat pattern "$###,###,###;-$###,###,###;#"( it can be different too) and I want to reformat the value in the AspxTextbox after deleting the ',' on GotFocus and LostFocus events by calling the following JavaScript function :

[code]....

I have tried to use ASPxFormatter but it is an internal class that is not indented to be used in a user project.Using String.Format('{0:' + displayFormat + '}', parseInt(value))); didn't work too , it threw an exception since String.format doesn't accept this format of pattern,Can you provide a way to reformat my string to any pattern I want not only the one I recite since ?

View 1 Replies

Format A Numeric String Using A Numeric Composite Format?

Aug 9, 2010

I've just encountered an interesting problem in a standard BoundField in a GridView. The field is for EmployeeCode, which is purely numeric, but stored in a character column in the database. The DataFormatString="{0:00000}" attribute on the BoundField doesn't work, as I assume that format is only for numeric values.

To work around this, I had to use a TemplateField, and bind the text value using the attribute Text='<%# PadNumericString(Eval("EmployeeCode").ToString(), 5) %>'. Is there no simpler way of doing this?

View 1 Replies

C# - How To Format A Timespan String

Feb 18, 2011

In the code i have :

gvRankings.DataSource = rankings.OrderBy(rg => rg.Swimtime).Take(100).ToArray();
gvRankings.DataBind();
(Swimtime here is a timespan)

At the frontside i have

< asp:TemplateField HeaderText="Tijd" ItemStyle-CssClass="time" HeaderStyle-CssClass="smallheader">
< ItemTemplate><%# ("Swimtime")%>< /ItemTemplate>
< /asp:TemplateField>

I would like to format the swimtime like hh:mm:dd.ff but i have (after 2 hours of trying) absolutely no idea how to do this.....

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved