Write String With Html I Made Codebehind Within A Panal?
Nov 12, 2010i have this string:
string foo = "<p>temp</p>";
how can i show it on my page without using Response.Write(foo)
i have this string:
string foo = "<p>temp</p>";
how can i show it on my page without using Response.Write(foo)
I'm interested to hear from other developers their opinion on an approach that I typically take. I have a web application, asp.net 2.0, c#.
What I usually do to write out drop downs, tables, input controls, etc. is in the code behind use StringBuilder and write out something like sb.Append("
I don't find myself using to many .net controls as I typically write out the html in the code behind. When I want to use jQuery or call JavaScript I just put that function call in my sb.Append tag like sb.Append("td...onblur='fnCallJS()'.
I've gotten pretty comfortable with this approach. For data access I use EntitySpaces.
I'm just kind of curious if this sort of approach is horribly wrong, ok depending on the context, good, time to learn 3.0, etc. I'm interested in learning and was just looking for some input.
Edit
After reading the comments here it sounds like I should take a look at MVC. I've not done that yet. The only hesitancy in doing so is that the existing project is just that, existing. There is a lot of code already done the way I explained and it is hard to imagine what would be involved in changing it, advantages of doing so, and just learning what that would take.
The other thing I'm taking away from the comments is that my code behind should really not include much of the sb.Append code, whereas now it is filled with it in numerous functions. To me it is not messy but that is because I know what each function does and can look at it and see, oh that writes out x, y, and z.
It's not uncommon for me to just have a div on the .aspx part and then build up the .innerHtml of that with the StringBuilder in the code behind.
In a C# codebehind, i am calling a web service that returns an HTML blob that i need to stick in an IFRAME. I suppose that i can write it to a temporary file and point the IFRAME src to that, but is there a way to either (a) write the string to the IFRAME directly, (b) point the IFRAME src to the string somehow (maybe with streams), or (c) some other way? I want to avoid writing this string to a file.
View 2 RepliesI have a dropdown with names of project managers and a checkboxlist with names of team members. What I want to do is write the IDs of selections made from the dropdown and checkboxlist to the DB. I am using the following code, but only IDs from the checkboxlist are stored in the table. What can I do to store the ID from the dropdown simultaneously? Thanks for your help.
for (int i = 0; i < project_members.Items.Count; i++)
{
if (project_members.Items[i].Selected)
[code]...
Can we set an id attribute as I would for something like a table column via: for an html dropdown list element that is created with a helper such as:
<% for (int i = 0; i < Model.Trx.TransactionHolidayCityCollection.Count; i++)
{%>
<%= i > 0 ? "," : "" %>
<%= DropDownData.HolidayDays().ToList().Find(item => item.Value == Model.Trx.TransactionHolidayCityCollection[i].HolidayCityID.Value.ToString()).Text %>
<%} %>
need to write radio button list with its items for each record table : qtext , a1 , a2 ,a3 ,a4qtest :display question texta1 - a4 :answers to choose between themi wrote this code but its only display it as html wont process it
[Code]....
I have an HTML table that has input values in labels. so bascially it is a big table with a lot of labels.
I need to know how to export it to excel, I have researched but I don't understand how to tell the excel file to get the necessary table.
I need a for below code
<HTML>
<Head>
</Head>
<Body>
<div id="div1" runat="server"> My Name is Guvera </div>
</Body>
</HTML>
In the above HTML i need to take a string "My Name is Guvera" using Asp.Net code.
is it possible to create a HTML Definition's List in the codebehind? I'm trying to pro grammatically generate the following HTML:
<dl style="overflow: hidden; font-size: small;">
<dt style="float: left; width: 200px; clear: both; text-align: right; margin-left: 15px;">Apple:</dt>
<dd style="float: left; width: 90px; margin: 0px 0px 8px;">Fruit<br>Red<br></dd>
</dl>
How can I get/retrieve html link (<a> tag) in my codebehind?
I have this link in the body of my website:
<a class="link1" id="link1" href="home.aspx>Test</a>
In my codebehind (Page_Load) I want to add a (Css)Class to it.
i would like to load a banner on to the page based on the registration count we have in the DB. if the registration count is >70, i will have to load banner2 on to the page. i am doing like this On the webForm.aspx
<img src="images/banner1.jpg"
runat="server"
id="imgs"/>
in the code behind
protected void Page_Load(object sender,
EventArgs e){
if (!Page.IsPostBack)
{
if(isSessionOneFilled())
{
imgs.Src = "images/banner2.jpg";
}
}
}
The above code works. is it Good Programming to load html files from codebehind? is there any alternative way? how does this impact when internet speed is slow?
I have an asp.net page where i have the below markup.Basically this markup is generated from codebehind by reading records from a table and looping thru them.For each record in table,there will be a div block. Basically this form is to read/show settings for a user.The settings entries are stored in a table.
<div id='divContainer' runat='server'>
<div id='div1' runat='server'>
<table>
<tr>
<th>Name</th>
<td><input type='text' id='txtName1' value='something' /></td>
</tr>
</table>
</div>
<div id='div2' runat='server'>
<table>
<tr>
<th>Domain name</th>
<td><input type='text' id='txtName2' value='something' /></td>
</tr>
</table>
</div>
<div id='div3' runat='server'>
<table>
<tr>
<th>URL</th>
<td><input type='text' id='txtName3' value='something' /></td>
</tr>
</table>
</div>
<div id='div4' runat='server'>
<table>
<tr>
<th>Some other value is enabled ?</th>
<td><input type='checkbox' id='chk4' /></td>
</tr>
</table>
</div>
</div>
The id's of each input element will be unique. Now in codebehind i want to read the values of each input elment to save the changes user made.How can i read the elements here ? Since the mark up is generated in codebehind as a string and appended the the INNER HTML of the external div,I cant read values like we do for a control which we drag and drop in the IDE.
I have a span control which I am filling using Jquery. At the page load I want this span say id1 to be invisible and depending on some conditions I am making it visible via jquery itself.
When I make id1 runat = server and try to access id1 from codebehing, then I get an error in Jquery.
Hence I need a way to make id1 invisble at the load time itself.
I have already set id1 = invisble in HTML, But still I see this control on the page till the time jquery fills the entire data.
i want to know, if is better to make an entire page in the aspx file or in the aspx.vb file...
if you have to decide, which one do you choose?
ie in aspx:
HTML Code:
[code]....
i want to know, if is better to make an entire page in the aspx file or in the aspx.vb file. If you have to decide, which one do you choose? ie in aspx:
Code:
<asp:Table ID="Table1" runat="server" Width="980">
<asp:TableRow>
<asp:TableCell>
SOME TEXT
</asp:TableCell>
</asp:TableRow>
</asp:Table>
ie in aspx.vb:
Code:
dim tabla as new table
tabla.id = "Table1"
tabla.width = 980
dim fila as new tablerow
dim celda as new tablecell
celda.text = "SOME TEXT"
fila.cells.add(celda)
tabla.rows.add(fila)
form1.controls.add(tabla)
I have a Sidemenu item in my ASP.NET application like below. There are two types of users in my application (Associates, Managers).When ever Associate Login then I have to disable Manager link. I am not able find visible property in codebehind since it is a HTML control. So need your support how to handle this
<ul>
<li><a href="Associate.aspx?val=Tests&index=0" id="lnkAssociates">Associate</a></li>
<li><a href="Manager.aspx id="lnkManager">Manager</a></li>
</ul>
I'm using VS 2008 and can't seem to get intellisense to reconise Public variables declared in my codebehind.I start a new ASP.NET Web Application project, named something other than "WebApplication1". In my default.aspx.vb codebehind, I declare, say, "Public MyValue As Integer = 10", at the class level of course.Then, in my default.aspx page, within the body tag, I type "<%= myvalue %>"No mater what I try, it refuses to recognise "myvalue" as a valid variable name, however the code DOES compile and runs perfectly. Everything else seems to work fine.
View 3 Replies //Read string contents using stream reader and convert html to parsed conent var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), null);
//Get each array values from parsed elements and add to the PDF document foreach (var htmlElement in parsedHtmlElements) pdfDoc.Add(htmlElement as IElement);
//Close your PDF pdfDoc.Close(); Response.ContentType = "application/pdf";
//Set default file Name as current datetime Response.AddHeader("content-disposition",
[Code] ....
Error: Input string was not in a correct format. Contents in html file giving error ...
I have to break a HTML content string in to multiple lines. And each line should have some fixed characters, 50 or 60 Also I don't want to break the word..or html tags...
ex : <p>Email: <a href="mailto:someone@gmail.com">someone@gmail.com</a></p>
<p><em>"Text goes <font color=red>Hello world</font> Text goes here and Text goes here Text goes here 1976."</em> </p>
How can I acheive this in C#?
how to write special string such as %31 to url.
View 4 RepliesWe are sending an HTML encoded string in the Query string. It was working fine on IIS 6 (windows 2003). We have recently moved the website to Windows 2008 (IIS 7.x). Since the move any Query String that contains "+" sign i.e., "%2b" gives error on the server "404 -File or directory not found."
View 2 Repliesi have a letter content in HTML in a string , i have to show it in a pdf format with all the styles and designs.
which possible method is there to convert it to pdf in C#,,
i have used itextsharp,but when styles,images comes in the HTML it never comes in pdf.
anyone knows how to replace a html tag in a string with specific characters:
e.g.
string s1 = "<span style="italic">inluding <span style="bold">other</span> tags </span>";
string s2 = "<span style="italic">inluding </span><span style="bold">other tags </span>";
i want to replace "span" with "bold" to "bOpen" and "bClose" and to replace "span" with "italic" to "iOpen" and "iClose" in both c# and javascript.
i did use regular expression to do that: res = Regex.Replace(res, ".*?", replaceHtmlBold); but it cant match the nested tag and none-nested tag at the same time.
I am using a code where I can upload a file to my other ftp. This code works without problem.
What it does is to create a file named TextFile1.txt
What I want to do is also to write a string to the uploaded file (putString) ?
What is needed to add to this code to do that.
[Code]....
What is the Best way to write my own HTML from code behind?
i currently use this :
<asp:Literal ID="ltr" runat="server"></asp:Literal>
and from code behind :
ltr.Text = "<p class="specific-class"></p>";
is it a right to do something like this?