In my Asp.NET page I have one html editor.
When user write below part, and click the save button this text is saved in database and gets the id number like (Id=12) and I get it from user interface side of web site with a page with below code.
<html>
<head></head>
<body>
...
..
.
</body>
</html>
I can get the saved text like below sql statement
SELECT Text FROM StackOverFlow WHERE Id = 12
And then I can show the value in web page.
In this respect I want to use this editor to create a asp.net textbox.
That is to say I want to create a new syntax which supply to editor entering basic sentences to create asp.net textbox.
Let's assume that syntax is below:
{{inputbox}}
<html>
<head></head>
<body>
<li>
{{inputbox}}
</li>
</body>
</html>
How can I create an asp.net textbox with using a new syntax like {{inputbox}}?
Can you give any advice to illuminate me?
I'd try looking at how the Razor view engine works. Or any ASP.net view engine.
I use some replace operations in HTML.
<html>
<head></head>
<body>
<li>
{{inputbox}}
</li>
</body>
</html>
I found {{ ...... }} and replace and dynamically create what I want.
You can try to do it using JQuery on client side by replacing {{inputbox}} with Text box.
var htmlStr = $(this).html();
htmlStr.replace('{{inputbox}}', '<asp:TextBox ID="DynamicName" runat="server"></asp:TextBox>');
$(this).html(htmlStr);
Related
I have stored html file in database. Now I would like to get data using cs file and link it to my view page. Below is my example of how I have save my able.
My database table contains two columns (page_header, page_footer).
page_header
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
page_footer
<footer>
<table width="100%">
<tr>
<td>
Written by Jon Doe.<br>
Visit us at:<br>
Example.com<br>
Box 564, Disneyland<br>
USA
</td>
<td>
Visit our Site
</td>
</footer>
I want to retrieve those data to my aspx page. Can anyone help in doing that. Or if any demo is available which will be helpful understand how to do that.
If this post is not related please don't degrade. Just let me know, I will delete it.
This is how you get user-specific information to your user without having to hand-update every single page you ever serve:
<!DOCTYPE html>
<html>
<head>
<title runat="server">Page Title</title>
</head>
<body runat="server">
<div id="welcomeDiv" runat="server"></div>
<div id="dataDiv" runat="server">
<datagridview id = "customerData" runat="server">
</div>
</body>
</html>
then, in your codebehind file:
private void Form1_Load(object sender, EventArgs e)
{
//load name from db
Form1.Title = "Welcome back, Mr. "+customer.LastName;
welcomeDIV.InnerHtml = "<b>It's been "+customer.daysSinceLastVisit.ToString()+" days since you last visited! How are "+customer.wifeName+" and the boys?</b>";
customerData = loadDataGrid(customer.ID);
}
It seems that you are creating some kind of a multi-tenant system and need a small amount of customization for each tenant.
There is no reason not to store HTML templates in a database—CMSes such as Wordpress do that a lot. However, to #ShannonHolsinger's point, you should ensure that your database schema is normalized to a reasonable extent. Consider storing e-mail address, contact name, address and website URL as separate fields.
For a templating system, there are many types of choices. You should explore some so you can choose one that is most familiar to you or your needs. In every case, though, be sure that data is property escaped to HTML or you could be allowing your page to be taken over. If you just paste strings together, such as by using InnerHtml then someone could enter their name as </div><script>ChangeTheEntirePageToWhatEverILike()</script> or </div><script>InjectInSomeCodeToSendFormDataToMySite()</script> and it would be seen by the browser as your code rather than as text.
One templating technique could involve client-side data binding. Some popular libraries are Knockout and Angular 2. For client-side data binding, you could put variable references in trusted header and footer HTML and then pass the variable values to be bound as JavaScript data. In other words, let the browser do any data merging that's needed rather than ASP.NET.
Im creating a website in c# asp.net,i desgined the master page,i added a link(our email id,indicating we are the developers)but,the content pages have gridviews which are not paged,so the length of the gridview varies based on the data,in all content pages using this master page.Because the length of gridview varies,when its long,the link's position seems to be in the middle of the page.I want our link to be in the bottom of the webpage.How to do this,pls help.
I think you html footer might be more useful to you.
<footer>
<p>Developed by: user2740323</p>
<p>Contact information: <a href="mailto:someone#example.com">
someone#example.com</a>.</p>
</footer>
you can add a footerPlaceHolder to your masterpage like this:
<asp:ContentPlaceHolder ID="FooterPlaceHolder" runat="server">
<div>
your info
</div>
</asp:ContentPlaceHolder>
am currently looking to implement the mobile menu system mmenu (http://mmenu.frebsite.nl/) into our Asp.Net site.
Works great on an HTML page and also in the Master page, so long as it's outside the form tag. When I put it within the form tag it no longer works.
Here is the HTML for the menu:
<nav id="menu">
<ul>
<li>The page</li>
<li>The mainmenu</li>
<li>Submenus</li>
<li>Labels</li>
<li>Counters</li
<li>Selected item</li>
<li>Open the menu</li>
<li>Close the menu</li>
</ul>
</nav>
This runs it fine:
<script type="text/javascript">
$(function () {
$('nav#menu').mmenu({
zposition: "next",
position: "top"
});
});
</script>
But then if I put it within the form tag (form id="MainForm" runat="server") I get a jquery error. Needs to be within as some menu items will come from the database.
Cheers
Simon
Mmenu does two things when it is initialized. First, it wraps the innerHTML of the <body> with a <div class="mmenu-page"> container, and then it cuts out the <nav> for the menus and moves those between the <body> and new page container in the DOM.
For whatever reason, it treats the ASP.Net wrapping <form> tag like the <body> tag, but only if it appears as the first child of the <body>. When this is the case, it inserts it's wrapping <div> immediately following the closing <form> tag.
If you wrap your ASP.Net <form> tag with an empty <div>, mmenu will be able to target it's <div class="mmenu-page"> correctly and everything magically works.
You'll want your code aspx page to look like this:
<body>
<div>
<form id="form1" runat="server">
...
<nav> ...mobile menu... </nav>
</form>
</div>
<body>
The empty div wrapping body didn't work for me. I found a post on GitHub that worked great:
$('#search-copy').mmenu({
// options
}, {
// config
offCanvas: {
menuWrapperSelector: "#aspnetForm",
pageNodetype: "form",
pageSelector: "body > form"
}
});
Here's the original post:
https://github.com/FrDH/jQuery.mmenu/issues/426
You may need to play around with your selectors. I ended up using an ID for pageSelector and a generic selector for menuWrapperSelector.
With mmenu, I found that there were a lot of hidden configuration and options settings. Some were in the mmenu docs, some were in the OffCanvas docs. Seems like the configuration/options settings will do just about anything you want without having to write a lot of custom CSS.
My application should parse the html and load the contents into the list box. I am able to get the html via webclient but got stuck parsing it.
I heard of Htmlagilitypack and Fizzler but couldn't find any tutorials or examples on their usage.
I want some help in grabbing "first_content" and "second_content" into a list box from the html document shown below.
<html>
<body>
<div>
<section>
<article>
<header>
<hgroup>
<h1>
first_content
</h1>
</hgroup>
</header>
<ul>
<li>
second_content
</li>
</ul>
</article>
</section>
</div>
</body>
</html>
HtmlAgilityPack is the way to go, I've been using it in WCF, Windows Phone and now WinRt with total success, for a tutorial check this blog post
You can use XPath. For example ...
var html = "<html><body><div><section><article><header><hgroup><h1>first_content</h1></hgroup></header><ul><li>second_content</li></ul></article> </section></div></body></html>";
var doc = new XmlDocument();
doc.LoadXml(html);
var txt1 = doc.SelectSingleNode("/html/body/div/section/article/header/hgroup/h1").InnerText;
var txt2 = doc.SelectSingleNode("/html/body/div/section/article/ul/li").InnerText;
jQuery and JavaScript can manipulate DOM like anything. But if C# has to send something to the client, then in my knowledge, we can only user Response object to write something in the browser. Now, this would write text in the browser, but we do not have control over where would it write it. Is there anyway that we can control from C#, somehting like :
"This is the text and I want it to be innerHTML of some particular DIV"?
You have two ways to go about doing something like this.
Make your div runat="server" and then it's accessible from the back end to manipulate
Register a JavaScript call using ClientScriptManager.RegisterClientScriptBlock and manipulate the div that way.
But also as Chuck has mentioned in his comment - that's a rather odd thing to do in ASP.NET. For the most part you'd use Label, Literal etc. server controls to add and manipulate text on a page instead of modifying native DOM elements directly.
That's not really how the internet works. When your browser navigates to a webpage, it sends a request to a server. The server responds with something. If it's trying to show a whole webpage, it needs the HTML of the whole page back. C# is powering the webserver.
When you browse to another page, you're not modifying an existing page; you're getting a whole new page back. We use JavaScript to get around that by letting it put out calls to webservers and use the information it gets back to modify the HTML on page, which it does know about, because it's running client-side.
So: no.
You can set the inner html of a div from your code behind. Just ad a runat="server" attribute to the div
<div id="divUserInfo" runat="server"></div>
and in your code behind
string strHtml="<h3> User Name </h3><p>User description</p>";
divUserInfo.innerHtml=strHtml;
This is in VB.NET, but I am sure C# has an equivalent. Just inject some javascript to do what you want.
ClientScript.RegisterStartupScript(Me.GetType, "myScript",
String.Format("<script>document.getElementById('{0}').innerHTML = '{1}';</script>", elementID, html))
.NET provides frameworks to do this - check out WebForms or MVC
From this article on MSDN:
<%# Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Message.InnerHtml = Server.HtmlEncode("Welcome! You accessed this page at: " + DateTime.Now);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HtmlContainerControl Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<span id="Message" runat="server"></span>
</div>
</form>
</body>
</html>