Reputation: 3050
I am creating HTML and ASPX file via C# code in APX everything works fine but in HTML page it appends the aspx tag which shows as plain text in body. i want to remove any text in body that starts with <%
and ends with %>
<body>
<center>
<%String action = "http://" + Request.Url.Authority+"/ABC/Data/a12.aspx" ; %>
<div>
<form>
// some input fields and a submit button
</form>
</div>
</center>
</body>
I have tried
document.body.innerHTML = document.body.innerHTML.replace( <%String action = "http://" + Request.Url.Authority+"/ABC/Data/a12.aspx" ; %>, "");
but didn't work for me, as the generated aspx tag is not same all the time..
Upvotes: 0
Views: 825
Reputation: 10547
Code Render Blocks shouldn't be rendered in HTML pages unless you're using them wrong. Try to modify your markup as follows:
<body>
<center>
<div>
<form action='<%= "http://" + Request.Url.Authority + "/ABC/Data/a12.aspx" %>'>
// some input fields and a submit button
</form>
</div>
</center>
</body>
Upvotes: 0
Reputation: 11
By using regular expression, I guess this should give what you need:
<script>
document.body.innerHTML = document.body.innerHTML.replace(/(<%).*(%>)/ig, '');
</script>
Upvotes: 0
Reputation: 20544
In this code:
document.body.innerHTML = document.body.innerHTML
.replace( <%String action = "http://" + Request.Url.Authority+"/ABC/Data/a12.aspx" ; %>, "");
You are: not using a string as the first argument, this is invalid.
I would suggest you to use a regex, that matches <% [anything] %>.
Like this:
document.body.innerHTML = document.body.innerHTML
.replace(/<%.*%>/g, "");
Upvotes: 1