Saturday, March 24, 2012

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.

No comments:

Post a Comment