Showing posts with label area. Show all posts
Showing posts with label area. Show all posts

Saturday, March 31, 2012

Submitting HTML page data through form.

Hi,

Iam trying to submit data using form.
I have taken Text area in the form.
I want to submit Html page data(data is something like <Html> <body> hello</body></html>)
through this form.

But it is giving error. How to handle this situation

Server Error in '/webs' Application.
------------------------

A potentially dangerous Request.Form value was detected from the client (ta=" <html><head></head><...").Please read the following:
Request Validation - Preventing Script Attacks

It will show you how you can effectively "turn off" this error. However, youmust take notice of the warnings in red text. Do not just turn off the error, without validating the input yourself.
Hi,

.NET 1.1 has built in protection against script injections through textbox, textareas etc., However, if you are sure that your users won't do the hacking, you can remove this checking functionality by adding the ValidateRequest="false" to the @.Page directive of your aspx page.

If you want this for whole of your application, you can specify the same in the web.config

Hope it helps.
Hello
Thanks for help.

It is working fine.

But While printing the result it is printing like
<html><head></head><body>hello</body></html>
How to handle this situation.
Hi there,

You will have to decode the information before actually bind to a control.

for e.g

Text1.text = Server.htmldecode(dr("myHtml).tostring)

HTH
Thanks to all .
It is running fine.

Thursday, March 22, 2012

Surface Area Calculator

I'm currently doing an assignment which calculates the surface area of a cylinder given the input of radius and height from the user and the answer is displayed in a read only control this is what I have so far

Class code

Public Class SurfaceAreaCalculator
Public Function calcSurfaceArea(ByVal r As Double, ByVal h As Double)
Const Pi As Double = 3.14159265
' r = radius, h = height
Return 2 * Pi * r ^ 2 + 2 * Pi * r * h

End Function

End Class

Form Code

Public Class WebForm1
Inherits System.Web.UI.Page

Dim SurfaceArea As New SurfaceAreaCalculator
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If IsPostBack Then
SurfaceArea = Session("SurfaceAreaClass")
Else
SurfaceArea = New SurfaceAreaCalculator
Session("SurfaceAreaClass") = SurfaceArea

End If
End Sub

Private Sub butcalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butcalculate.Click

Me.txtanswer.Text = SurfaceArea.calcSurfaceArea

I keep getting an error in the button click event procedure,and am having trouble displaying the answer using the formula above

Any tips would be appreciated ThanksPublic Class SurfaceAreaCalculator
Public Function calcSurfaceArea(ByVal r As Double, ByVal h As Double)
Const Pi As Double = 3.14159265
' r = radius, h = height
Return 2 * (Pi * r ^ 2) + (2 * Pi * r) * h

End Function

End Class

Public Class WebForm1
Inherits System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If not IsPostBack Then
Session("SurfaceAreaClass") = New SurfaceAreaCalculator
End If
End Sub

Private Sub butcalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butcalculate.Click
Dim SurfaceArea as SerfaceAreaCalculator = Session("SurfaceAreaClass")
Me.txtanswer.Text = SurfaceArea.calcSurfaceArea(Put something in here)
Thanks for that you've been a great help, would it be possible to help with the following as well

The program also requires that the user enters a double precision number between 0 and 5000 for the radius textbox and a double precision number between 0 and 10000 for the height textbox, the answer displayed in the third text box also has to be to 2 decimal places

I have used a required field validator control to ensure the textboxes can't be blank, but unsure on how to make sure the values are both double precision and in between those ranges I probably also would need to ensure the user can't enter non-numeric data

Any tips/advice on the above would be appreciated as I'm new to the language and still learning

Thank-you
Use a regex validator with your required field validator. Here's an example

<asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server"
ErrorMessage="Please enter a double precision number between 0.00 and 5000.00"
ValidationExpression="(^5000\.00$)|((^[0-4]\d{3}|^\d{0,3})\.\d\d$)" ControlToValidate="TextBox1">
</asp:RegularExpressionValidator>

The validationexpression value breaks down like this
(^5000\.00$) - Match 5000.00
| or
^[0-4]\d{3} - Match any number starting with 0 through 4 ending in any three digits. This will match 0000-4999
^\d{0,3} - Match any number starting with 0 through three digits long. 0 - 999
\.\d\d$ - Match numbers ending with a decimal and any two numbers.
Thanks for your help