.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Dynamically modify HTML markup

Posted By:      Posted Date: September 22, 2010    Points: 0   Category :ASP.Net

Hi, I have a Master Page as well as a standard Web Form aspx file. What if I wanted to dynamically modify the complete HTML markup in an aspx file (perhaps based on a conditional statement - perhaps in a specific content place holder), how would I go about doing this? Sorry I'm coming from a PHP background so this is why I'm asking such a simple question.

View Complete Post

More Related Resource Links

dynamically change html code when user is authenticated


So I have a fairly simple web site which allows an Administrator to edit some data in a database which is displayed on some web pages.

The main navigation on the site is shown in the code snippet below. The Admin link goes to a Login.aspx which allows the Administrator to log in - once authenticated they get sent to the data edit page.

So my question is, how could I dynamically add a link to the data edit page in the <ul> list below once the user is authenticated ?

This would allow the authenticated user to see links to the secure pages in the main navigation bar.

<%--Top Navigation Menu --%>
<div id="topMenu">
<li><a href="default.aspx">Home</a></li>
<li><a href="introduction.aspx">Introduction</a></li>
<li><a href="curriculum.aspx">Curriculum</a></li>
<li><a href="times.aspx">Times & Fees</a></li>
<li><a href="staff.aspx">Staff</a></li>
<li><a href="login.aspx">Admin</a></li>
</div><%--End of topMenu Container--%>
<div id="clear"></div><%--Floats items cleared End of Master Page--%>

SQL Server + ASP.NET Security Validation + HTML Markup Security

Hey everyone!I have an application, that for example, the customer gives me their Address. I store it in my database using the below code:        Dim connectionString As String = ConfigurationManager.ConnectionStrings("DMBConnstring").ConnectionString         Dim insertSql As String = "INSERT INTO BasicUserProfile(UserGuid, Firstname, Lastname, Nickname, Address1, City, State, Zip, DOB, Gender, SeekingGender, Sexuality, SeekingSexuality, HaveKids, WantKids, BodyType, SeekingBodyType, Ethnicity, SeekingEthnicity, Religion, SeekingReligion, Smoking, SeekingSmoking, Education, SeekingEducation, Relationship, SeekingRelationship) " _         & "VALUES (@UserGuid, @Firstname, @Lastname, @Nickname, @Address1, @City, @State, @Zip, @DOB, @Gender, @SeekingGender, @Sexuality, @SeekingSexuality, @HaveKids, @WantKids, @BodyType, @SeekingBodyType, @Ethnicity, @SeekingEthnicity, @Religion, @SeekingReligion, @Smoking, @SeekingSmoking, @Education, @SeekingEducation, @Relationship, @SeekingRelationship)"         Dim connectionString As String = ConfigurationManager.ConnectionStrings("myconnstring").ConnectionString        Dim insertSql As String = "INSERT INTO BasicUserProfile(UserGuid, Firstname, Lastname, Nickname, A

Visual Studio adds " " to html markup

Reference topic: http://forums.asp.net/t/1192748.aspx I hav just spent close on 1.5 hours fixing the exact same problem outlined in the topic above. Just a bief outline: I made some changes to my page in code view, and clicked save. At that point, Visual Studio just added close on 40 000 (!!!) $nbsp; to every possible area in the page. It seemed to, however, like putting these into the table that was on the page. VS also seemed to add a new tag <caption></caption> all over the show. To top it off, it completely destroyed my table layout by adding random <td></td> tags. I had to now resort to fixing the markup manually in notepad, since doing a search & replace in both notepad and VS left vast chunks of whitespace in the markup, and fixing it in VS just added it back again. The net result is that my indentation is now completely destroyed.   Is there a permanent fix for this issue? (I am running Visual Studio 2008 SP1 Team Edition)

How to dynamically create HTML file from the code ?

Hi all,Precisely and concisely, I have aspx page that has only one button "Generate". If the user clicked on this button, one HTML page should be created. The created HTML page should have title "Home" and the Body should contain "Hello World". 1) What is the code that should be written inside "Generate" button in order to accomplish this functionality? 2) Assuming the HTML page gets created, How to store it inside specific folder on the local drive? Or how to store it inside DB? I would greatly appreciate any constructive input!

How to get value from dynamically added html input?


Hi everyone,

 I'm struggling with the Javascript problem and need some help. On my page, I have a Javascript function that allowed users to add a text input with different ID:

<script language="javascript" type="text/javascript">
        function addElement() {
            var ni = document.getElementById('myDiv');
            var numi = document.getElementById('theValue');
            var num = (document.getElementById('theValue').value - 1) + 2;
            numi.value = num;
            var newdiv = document.createElement('div');
            var divIdName = 'my' + num + 'Div';
            newdiv.setAttribute('id', divIdName);
            newdiv.innerHTML = '<b>Citation ' + num + ': </b><input type="text" id="citation' + num + '" size="100%" />';

How do I get these Javascript-generated input elements after the user submits the form? 

Thanks for help,



HTML and asp.net markup!




I want to know how the server will process my page that contain:

 1- ASP.NET markup mixed with HTML elements.

2- Code behinde.


Will it read the ASP.NET markup line by line and even HTML elements?

And then reads the code behind? or what exactly?


When binding value to ImageUrl property of Image using XPath it shows code as html markup on fronten


I have a listview in which I want to show an image from an xmldatasource control.

The following works, and shows the value of thumb (in this case: 12_634232073402187500_whatever.jpg)

<asp:ListView ID="repLocationsToCompare" ItemPlaceholderID="itemsGoHere" runat="server">
            <%# XPath("thumb")%>
<asp:XmlDataSource EnableCaching="false" XPath="root/data/compare/locations/location" ID="XMLDSCompare" runat="server"></asp:XmlDataSource>

No problem there, BUT, when I use an imagecontrol:

<asp:ListView ID="repLocationsToCompare" ItemPlaceholderID="itemsGoHere" runat="server">
            <asp:Image ID="img" Visible='<%# XPath("thumb

Any better than jquery dynamically write html code?


I am creating a page which contains one grid showing the content from a very slow data source. There are other faster contents to be displayed too.

I know I can use jquery to dynamically generate the html code from a dedicated controller for the slow data source. 

However, it's not intuitive to read the jquery code for the grid. is there any better way?

Regular expression for Ms Word HTML Markup


I am trying to create a regular expression that searchs for all html tags and attributes that start with 'mso', ending with a semi-colon.  If found, it would replace it with an empty string.

eg. Input string:

<span style="font-family: Arial, sans-serif; font-size: 11pt; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: Times New Roman; mso-bidi-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">My text goes here</span>


<span style="font-family: Arial, sans-serif; font-size: 11pt;">My text goes here</span>

All the attempts I have tried have yielded no results. I have tried: (\bmso)\w*[;]\b and this - \bmso\w+(?=;\b) among many other variations of the two.  Any help would be appreciated.


Regular expression for MS Word HTML Markup


I am trying to validate a rich text box to remove some ms word content but I want to keep the other attributes that are not MS office related.

input: <span style="font-size: 11pt; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: &#34;Times New Roman&#34;; mso-bidi-font-family: Times New Roman&#34;; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; font-family: Arial&#34;, &#34;sans-serif&#34;">mso-bidi-language: AR-SA; mso-My Text Here; mso-My Text Here2</span>

I first run this regex to remove the unformed html (\&\#34\;).  Then, I remove everything inside the =" ending with "

regex: (?<=\=\")(.*?)(?=\")
: <span font="" style="">mso-bidi-language: AR-SA; mso-My Text Here; mso-My Text Here2</span>

Now it removes everything inside the tags and not the text. With the following, it removes the matching pattern, but it also removes the text that i need and the end tags.

: <span font="font-size: 11pt;" style="font-family: Arial, sans-serif;">

When i try and combine the two expressions, it does not provide the correct output.

RichHtmlField showing html markup in display mode



Can somebody provide a solution to my problem? I have a RichHTMLField that I created in sharepoint designer/Visual Studios. After I got everything to work. I've tested it on several computers and it worked fine. When I tried it on my computer, my RichHtmlField in my sharepoint  shows html markup in display mode. In the edit mode, it shows perfectly fine and well formatted. When I save and publish it out, the published mode shows the actual HTML markup like you would see in WYSIWYG interface.

Any solutions?

ASP.NET, HTML, JavaScript Snippet Support (VS 2010 and .NET 4.0 Series)

This post covers another useful improvement in VS 2010 - HTML/ASP.NET/JavaScript snippet support. Snippets allow you to be more productive within source view by allowing you to create chunks of code and markup that you can quickly apply and use in your application with a minimum of character typing.

Visual Studio has supported the concept of "snippets" for VB and C# in previous releases - but not for HTML, ASP.NET markup and JavaScript. With VS 2010 we now support snippets for these content types as well.

Microsoft's Collaborative Application Markup Language (CAML) Loop

discovered an interesting error recently while working with Microsoft's Collaborative Application Markup Language (CAML) that, surprisingly, had received no ink. Partly what surprises me about this is that the error may require you to rewrite large sections of your code if you haven't previously considered this SharePoint limitation. I'll start with some context, but first of all the error is:

Maintain HTML Radio Button Selection Inside GridView After Postback

Long time ago I wrote an article about getting the value of the selected RadioButtons inside the GridView control. The code did not addresssed the postback issue which means that the selected radio button was cleared after the postback occurs.

Rendering ASP.NET Script References into the Html Header

One thing that I've come to appreciate in control development in ASP.NET that use JavaScript is the ability to have more control over script and script include placement than ASP.NET provides natively. Specifically in ASP.NET you can use either the ClientScriptManager or ScriptManager to embed scripts and script references into pages via code.

Dynamically Create Controls in ASP.NET by Using Visual C# .NET

This article demonstrates how to dynamically create a control for an .aspx page. The sample project does the following:
Creates two TextBox controls.
Verifies that the contents (TextBox.text) and the attributes of the TextBox are saved across posts to the server.
Illustrates handling events that are posted by a dynamically-created control
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend