troyvw
asked on
ASP.net get the value of a div tag into a string variable
How would i get the value of the inner html of a html div tag into a asp.net variable
ASKER
I did this in my html:
<div id="header1" runat="server"</div>
and tried this in my code
div1.Controls
and it did not know what header1 was.
<div id="header1" runat="server"</div>
and tried this in my code
div1.Controls
and it did not know what header1 was.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.c s" Inherits="WebApplication1. _Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="div1" runat=server>
Sample
</div>
</form>
</body>
</html>
-------------------------- ---------- ---------- ---------- ---------- ---------- --
using System;
using System.Collections.Generic ;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("From Code : " + div1.InnerHtml);
}
}
}
-------------------------- ---------- ---------- ---------- ---------- -----
output
From Code : Sample
Sample
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="div1" runat=server>
Sample
</div>
</form>
</body>
</html>
--------------------------
using System;
using System.Collections.Generic
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("From Code : " + div1.InnerHtml);
}
}
}
--------------------------
output
From Code : Sample
Sample
ASKER
I can read my div tags in asp.net but they are all blank even though I put something in the inner html
u placed div tag in the same manner ???
<div id="div1" runat=server>
Sample
</div>
<div id="div1" runat=server>
Sample
</div>
can u provide ur code pls
ASKER
HTML
<div id="IntroPar" runat="server"></div>
asp.net code:
strhtml = IntroPar.InnerHtml
<div id="IntroPar" runat="server"></div>
asp.net code:
strhtml = IntroPar.InnerHtml
ASKER
That code returns "" for strhtml
there is nothing in between the div tag... as per ur code...
so it will return ""
check and compare my code snippets given... and it gives wht ever there in between the div opening and closing tags
hope u got the thing.
so it will return ""
check and compare my code snippets given... and it gives wht ever there in between the div opening and closing tags
hope u got the thing.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get a error
Cannot get inner content of header1 because the contents are not literal
Cannot get inner content of header1 because the contents are not literal
ASKER
Never mind on my last post i figure that portion out...
maybe i should mention header i am setting the innerhtml in code
div1.innerhtml = "TEST"
maybe i should mention header i am setting the innerhtml in code
div1.innerhtml = "TEST"
ASKER
it worked thanks
For that, put the attributes runat= "server" and id="div1"
n in ur code behind u can try like, div1.Controls