Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Thursday, March 29, 2012

HTML in a variable

Im using asp on a win2k3 server. I would like to put a lot of html into 1 variable. I get an error when i try to do it my way.


'Here is an example of what I would like to do, kinda.
application="<html>
<head>
<title>Join</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="http://links.10026.com/?link=join.css" rel="stylesheet" type="text/css">
</head>"


'Here is the error.
Microsoft VBScript compilation error '800a0409'

Unterminated string constant

/cfcs/join/mail.asp, line 17

application="<html>
------^

I was wondering if anyone could suggest an effective method of doing this.you should replace the double quotes(") by a single quote(') and instead of adding new line for the variable value you can use <br
application="<html><br><head><br><title>Join</title><br><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'><br><link href='join.css' rel='stylesheet' type='text/css'><br></head></html>"

Hope this helps
Nitasha

------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
this isn't an asp forum

application = "<html>" & vbCrLf & "<head>" & vbCrLf & "<title>Join</title>" & vbCrLf & "<meta http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"">" & _
vbCrLf & "<link href="http://links.10026.com/?link="join.css"" rel=""stylesheet"" type=""text/css"">" & vbCrLf & "</head>"
The new lines in the string are not understood by VB.

HTML from code behind

Hi,
A hopefully simple question for someone to answer. I wish to dynamically change the HTML code from VB code behind. For example I have a table setup in the HTML code and what I want to do is display formatted text within this table that has been placed dynamically by code behind, depending on a querystring. See example below

<td width="300" rowspan="13" valign="top"><p></p
(CODE TO PLACED HERE BY CODE BEHIND)
</td
Above a table is defined in HTML, but I want the below code to be placed into this table by using code behind (this will be dependent on a querystring so that different text will be displayed depending on what link was used)

<p align="right"><font face="Arial, Helvetica, sans-serif">This
is a test
</font></p>
<p align="justify"><font face="Arial, Helvetica, sans-serif">Want
this sample to be sent from the code behind. How can it be done?</font></p
Can anyone please help?
ThanksYou may use <asp:table/> control and add tablerow and tablecell at run time.
Thanks for that, I had a look in MSDN and that will work fine for creating the tables, rows and cells but what about the formatted text. I noticed that there is innerhtml, could you please explain how I could use this. Would I be able to create a static table, that is written in HTML but add "runat = server" in the table definition. Then add HTML from code behind using innerHTML. I have tried getting it to work but I keep getting syntax errors. Any thoughts would be great.

Thanks
James
The easiest way (I think) is to put a placeholder where you want your dynamic text to go:

<table>
<tr>
<td>
<asp:Placeholder id="TableCellPlaceholder" runat='server" />
</td>
</tr>
</table>

In your codebehind, you of course define this placeholder:

Protected TableCellPlaceholder As System.Web.UI.WebControls.Placeholder

Then, when you get to adding the dynamic text, you just add it as a LiteralControl:

Dim HtmlTtoInject As String
If Request.Params( "s" ) = "Google" Then
HtmlToInject = "< b>Thanks for choosing Google</b>"
Else
HtmlToInject = "< i>It's time you tried Google</i>"
End If
TableCellPlaceholder.Controls.Add( New LiteralControl( HtmlToInject ) )

This is admittedly a quick and dirty approach ... however, it's also perhaps the easiest.

Hope this helps.
Great, that works just how I wanted. Thank you :)

You did say:
"This is admittedly a quick and dirty approach ... however, it's also perhaps the easiest."

What other way may you do this? Just for future reference.

Thanks again
Well, it's more "object-oriented" to do what JimmyM said, and create TableRow objects, which contain TableCell objects, which in turn contain Label objects or Literal objects ... and then attach the TableRow objects to your Table object.

But, you can do that later when you need a more structured approach to dynamically building a table.

For the simple purpose you said, using a Placeholder is nice and easy.
Just put in an <asp:label> control and use this code:

label1.InnerHtml="Here is some HTML code <bthis is in bold</b> this is a link

Hope this helps

Colin Cameron

Monday, March 26, 2012

HTML Form value retrieval

Yes. If you use the action attribute, it works fine. Here's an example, from
this working page
http://www.pmaconference.com/specia...04/register.htm

<form name="form" onsubmit="return(sendReg())"
action="https://energycatalogue.acomhosting.com/orderform.aspx"
"Matt" <anonymous@dotnet.itags.org.discussions.microsoft.com> wrote in message
news:F7ED5A87-B31F-4BA8-A0A2-CFC966462174@dotnet.itags.org.microsoft.com...
> I have an aspx page whose purpose is to read a customer-provided HTML
form, display it, and reads the values from it on a postback. I cannot seem
to read the values from Request.Form when this type of form is posted back.
All I am trying to do is loop through the items in Request.Form and store
their values for later use in the application. Neither the "form" tag nor
the control tags use the runat="server" attribute since this is a
customer-created form that we would like to be standard HTML to allow full
control of the form contents, and look and feel of the form. There will
only ever be one client-side form per rendering of the page. By adding the
runat="server" attribute to the form tag, I have been able to see only one
item in the Request, _VIEWSTATE. None of the other HTML controls will
appear in the collection. Is this type of thing possible?Thanks for the reply. Even with the action on the form, I the Request.Form.Count value is also zero when I do a postback. Obviously there's something wrong, probably very basic. Below is the form that I am testing with. I've tried with and without the METHOD and ACTION attributes

<form name="autos" method="post" action="http://cregosource/privateparty/formdata.aspx"><input type="checkbox" id="check" value="checkvalue"><br><input type="checkbox" id="check2" value="checkvalue2"><br><input type="text" id="text" value="333333"><textarea id="mytextarea">asdf</textarea><input type="radio" id="myradio" value="1"><input type="radio" id="myradio" value="2"><input type="radio" id="myradio" value="3"><select id="myselect" size="5"><option>1</option><option>2</option></select><select id="myselectmultiple" size="5" multiple><option value="1">one</option><option value="2">two</option><option value="3">three</option><option value="4">four</option><option value="5">five</option></select><br><br><input type="submit" value="Submit"></form

And here's the code in a codebehind page that I'm debugging

if (Request.Form.Count>0)

foreach (string strReq in Request.Form)

oTrans.KeyAddOrReplace(PrivateParty.TranState.Sect ionType.Form,strReq,Request[strReq])

oTrans.SaveState()

Even if I omit the Count test, there are no items in the Form. Does it pose a problem if I am using usercontrols on this page? I do not specifically call out any form tags in these controls. Any additional help is much appreciated!

html error

i have a freetextbox that is a htmleditor , but when i want to send my html to server an error raise.
for example i want to send this line

hello

this error raises :
A potentially dangerous Request.Form value was detected from the client (ftbCaption="<STRONG>hello</STRON...")

how can i pervent this error?check out the FTB forums
http://www.freetextbox.com/forums/ShowPost.aspx?PostID=496

short anwser = put this line in your page directive:
ValidateRequest=false

that worked for me

Saturday, March 24, 2012

HTML E-Mail in 2.0

I am converting an ASP.NET 1.1 application to 2.0 that submits an HTML
e-mail trough SMTP.

Is there a simple example of how to sent an HTML e-mail in 2.0? Must you
always use plain text in the body and create an HTML alternate view? Is
there an example available?

--
-- Thom Little -- www.tlanet.net -- Thom Little Associates, Ltd.
--http://www.systemnetmail.com/faq/3.1.2.aspx
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"Thom Little" <thom@.tlanet.netwrote in message news:urR9n8BsGHA.4244@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>I am converting an ASP.NET 1.1 application to 2.0 that submits an HTML e-mail trough SMTP.
>
Is there a simple example of how to sent an HTML e-mail in 2.0? Must you always use plain text in
the body and create an HTML alternate view? Is there an example available?
>
--
-- Thom Little -- www.tlanet.net -- Thom Little Associates, Ltd.
--
>
>
>


"IsBodyHtml" is what I was overlooking.

It is working now.

Thank you.

--
-- Thom Little -- www.tlanet.net -- Thom Little Associates, Ltd.
--

"Juan T. Llibre" <nomailreplies@.nowhere.comwrote in message
news:OGcQk$BsGHA.4116@.TK2MSFTNGP06.phx.gbl...

Quote:

Originally Posted by

http://www.systemnetmail.com/faq/3.1.2.aspx
>
>
>
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/


You're quite welcome.
Glad to know you're up and running.

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"Thom Little" <thom@.tlanet.netwrote in message news:O%23xznMCsGHA.4324@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>
"IsBodyHtml" is what I was overlooking.
>
It is working now.
>
Thank you.
>
--
-- Thom Little -- www.tlanet.net -- Thom Little Associates, Ltd.
--
>
"Juan T. Llibre" <nomailreplies@.nowhere.comwrote in message
news:OGcQk$BsGHA.4116@.TK2MSFTNGP06.phx.gbl...

Quote:

Originally Posted by

>http://www.systemnetmail.com/faq/3.1.2.aspx
>>
>>
>>
>Juan T. Llibre, asp.net MVP
>aspnetfaq.com : http://www.aspnetfaq.com/
>asp.net faq : http://asp.net.do/faq/
>foros de asp.net, en espaol : http://asp.net.do/foros/


>
>

HTML Elements vs. WebControls?

What are the pros and cons to using each?

For example, why should I use the asp.net textbox instead of the HTML element textbox?

This has been confusing me for awhile now.

Thanks for any input.

JamesHTML server controls
==============
HTML elements exposed to the server so you can program them. HTML server controls expose an object model that maps very closely to the HTML elements that they render.

Web server controls
=============
Controls with more built-in features than HTML server controls. Web server controls include not only form-type controls such as buttons and text boxes, but also special-purpose controls such as a calendar. Web server controls are more abstract than HTML server controls in that their object model does not necessarily reflect HTML syntax
Web Server controls require more overhead... if you are concern about performance then I woud go with Html server controls. (Not a huge difference though...)

HTML Elements and Web Control Elements ...

hi all, I am a little confused about when to use html/web controls elemetns in my asp.net pages. Like this example, if I am using textbox1.text = cstr(session("emailAddress")) ... it works fine ... but, if the text box is an html element, I can't assign the session data to the text box by writing: request.form("EmailAddress") = cstr(session("emailAddress")) ... it will have error saying: Collection is for read-only :( I am trying to passed a session data to another page and display it in an html textbox ... how can I do that? And, if html elements also can display session data as well as web controls elements, what is the purpose of including two contols in asp.net web matrix?? Need help and advice .. thank you.

my email page code looks like this:-
===========================

Sub Page_load(Sender as Object, E as EventArgs)

textbox1.text = cstr(session("emailAddress")) 'this works fine

request.form("EmailAddress") = cstr(session("emailAddress")) 'not working :(

If request.form("EmailAddress") = "" Then
dim strResponse as string = "<h2>Send Email using ASP.NET formatted in HTML</h2>"
lblMessage.Text = strResponse
Else
dim strResponse as string = "You just sent an email message formatted in HTML to:<h2>" & request("EmailAddress") & "</h2>"
lblMessage.Text = strResponse
End If

End Sub

Sub btn_Click(sender as Object, e as System.EventArgs)

If request.form("EmailAddress") <> ""
Dim mail As New MailMessage
mail.From = "email@dotnet.itags.org.yahoo.com"
mail.To = request.form("EmailAddress")
mail.Subject = "Message sent using ASP.NET and CDONTS"
mail.Body = "HTML Message sent from ASPFree.com using ASP.NET and Cdonts" & "<a href=http://aspfree.com/aspnet/email.aspx>Wonder how this is done?</a>" & "<a href=http://aspfree.com/aspnet/setupcdonts.aspx>Wonder How to setup CDONTS?</a>"
mail.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer = "19.204.22.166"
SmtpMail.Send(mail)
End If
End Sub

you can set an html textbox value the same way you did in ASP.

<input type="textbox" value="<%=Session("emailaddress")%"
the server controls give you a great deal of flexibility when building a web page. The code behind makes programming a web page more like programming a windows form. each server control does have overhead however, so if you dont need the extra functionality provided by making the control a runat=server, then you should stick to regular HTML elements.

html editor for update pages contents

Hello,
I develop a Web site ASP.NET which contains dynamic pages (example: News .).
I would want that the administrator of site can add and update contents in
these pages with formatting options (example: colors, fonts.); I believe
that the solution is a small html editor.
Somebody could help me or show me how to make?
Quite other idea will be welcome.
Thank you in advance.
NoroHi Noro,
You might want to check out the free editor that comes with DotNetNuke:
http://www.dotnetnuke.com/
Ken
Microsoft MVP [ASP.NET]
"Noro" <noureddine@.astoine.com> wrote in message
news:%23eWu7VWhGHA.3572@.TK2MSFTNGP04.phx.gbl...
> Hello,
> I develop a Web site ASP.NET which contains dynamic pages (example: News
> .). I would want that the administrator of site can add and update
> contents in these pages with formatting options (example: colors, fonts.);
> I believe that the solution is a small html editor.
> Somebody could help me or show me how to make?
> Quite other idea will be welcome.
>
> Thank you in advance.
> Noro
>

html editor for update pages contents

Hello,

I develop a Web site ASP.NET which contains dynamic pages (example: News .).
I would want that the administrator of site can add and update contents in
these pages with formatting options (example: colors, fonts.); I believe
that the solution is a small html editor.

Somebody could help me or show me how to make?

Quite other idea will be welcome.

Thank you in advance.

NoroJust a remark: My idea is to integrate the html editor into the
administration interface of the site.

Thank you in advance,

Noro

"Noro" <noureddine@.astoine.com> a crit dans le message de news:
%23eWu7VWhGHA.3572@.TK2MSFTNGP04.phx.gbl...
> Hello,
> I develop a Web site ASP.NET which contains dynamic pages (example: News
> .). I would want that the administrator of site can add and update
> contents in these pages with formatting options (example: colors, fonts.);
> I believe that the solution is a small html editor.
> Somebody could help me or show me how to make?
> Quite other idea will be welcome.
>
> Thank you in advance.
> Noro
Hi Noro,

You might want to check out the free editor that comes with DotNetNuke:

http://www.dotnetnuke.com/

Ken
Microsoft MVP [ASP.NET]

"Noro" <noureddine@.astoine.com> wrote in message
news:%23eWu7VWhGHA.3572@.TK2MSFTNGP04.phx.gbl...
> Hello,
> I develop a Web site ASP.NET which contains dynamic pages (example: News
> .). I would want that the administrator of site can add and update
> contents in these pages with formatting options (example: colors, fonts.);
> I believe that the solution is a small html editor.
> Somebody could help me or show me how to make?
> Quite other idea will be welcome.
>
> Thank you in advance.
> Noro

Thursday, March 22, 2012

HTML control Vs Web form control

Hi,

I am new to asp.net. I want to know that, HTML and Web form control can work
in same way example, using "runat = Server" attribute, html control can also
executed at server, then what is the use of HTML control and is there is any
specific condition when we use only HTML control or web form control.

Thanks and regards,
Bhuwan"Bhuwan Bhaskar" <kxxx@.gmail.comwrote in message
news:uxe%23IJ4HIHA.4560@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

I am new to asp.net. I want to know that, HTML and Web form control can
work in same way example, using "runat = Server" attribute, html control
can also executed at server, then what is the use of HTML control and is
there is any specific condition when we use only HTML control or web form
control.


http://www.google.co.uk/search?sour...ls+HTMLControls
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Html controls are lighter. One of typical scenarios where you may want to
use html controls is when you have an html prototype of your page and you
need to program it in asp.net. Then it is easier just to add runat=server to
html controls.

Web controls offer common set of server-side members that can make your code
cleaner and more readable.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Bhuwan Bhaskar" <kxxx@.gmail.comwrote in message
news:uxe%23IJ4HIHA.4560@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

Hi,
>
I am new to asp.net. I want to know that, HTML and Web form control can
work in same way example, using "runat = Server" attribute, html control
can also executed at server, then what is the use of HTML control and is
there is any specific condition when we use only HTML control or web form
control.
>
Thanks and regards,
Bhuwan
>

html code of web controls

is there any way i can get the corresponding HTML code of a web control?

For example, i have an asp.net table with w/ one row and one cell with the text "sample". I want to get this string:

"<table><tr><td>sample</td></tr></table>"

Is this possible?i guess you could put the web control on your page, press the run button,then right click on the webbrowser,nd in the context menu click view source, you can find the html code for you control there
Yeah, but I need to retrieve the html code from the program. Anyway, I have already solved it. Here's the code I used:

//returns the html code of the specified web control
public static string RenderHTML(System.Web.UI.WebControls.WebControl control)
{

StringBuilder SB = new StringBuilder();
System.IO.StringWriter SW = new System.IO.StringWriter(SB);
System.Web.UI.Html32TextWriter htmlTW = new Html32TextWriter(SW);
control.RenderControl(htmlTW);
string html = SB.ToString();
return html;
}