Classic ASP formatnumber error - asp-classic

I am new to classic asp and so I am trying to understand the below code which is causing an error
<input class="uploadCalcField" type="text" size="12" name="<%="upload" & "z" & rs("e_cat_id") & "z" & l2_id & "z" & l1_id%>" value="<%=formatnumber(Request.Form("upload" & "z" & rs("e_cat_id") & "z" & l2_id & "z" & l1_id), 0)%>" onClick="this.blur();">
the error is
type mismatch: 'formatnumber'.
I have checked the output of
Request.Form("upload" & "z" & rs("e_cat_id") & "z" & l2_id & "z" & l1_id)
and it's empty which seems to be the cause, can anybody help me to understand the error?

The FormatNumber() fails because as you point out in the question the value it is trying to format that comes from Request.Form() is empty.
The Request.Form collection is built by Classic ASP when a HTML form is submitted to Classic ASP using the POST method.
Here is a simple example
<html>
<head>
<title>Test Form Submission to Classic ASP</title>
</head>
<body>
<form method="POST" action="/test.asp">
<input type="text" name="testinput" value="hello world" />
<input type="submit" value="Submit Form" />
</form>
</body>
</html>
When the Submit Form button is pressed in the Browser a HTTP request is generated and sent off to the Web Server, in this case to Classic ASP to process.
POST http://example.com/test.asp HTTP/1.1
Host: example.com
testinput=hello%20world
*More headers would be passed but removed to keep the example simple
Classic ASP takes the string of key-value pairs and populates the Request.Form collection
test.asp (called when Submit Form button is pressed in HTML page)
<%
Call Response.Write(Request.Form("testinput"))
%>
Output:
hello world

Related

Replicating remote site "attack" by force sending specific form data to a page

I have this simple form:
<form method="post" id="theForm" action="user-password.asp">
<input type="hidden" name="what" value="process" />
<fieldset>
<div>
<label for="email">Username or Email</label>
<input type="text" class="form-control" id="email" name="email" placeholder="Username or Email" />
</div>
<div>
<button type="submit" class="btn btn-success top10">Submit</button>
</div>
</fieldset>
</form>
I have a script which emails me when my Classic ASP pages error - I use this to get all of the form contents:
For ix = 1 to Request.Form.Count
fieldName = Request.Form.Key(ix)
fieldValue = Request.Form.Item(ix)
bb = bb & fieldName & ": " & fieldValue & vbcrlf
Next
bb = newstr(bb)
For the above page, the page errored with:
A trappable error (C0000005) occurred in an external object. The script cannot continue running.
The form contents were like this:
form: email[$acunetix]: 1
what: process
In order to improve the error handling on the page, I'd like to be able to replicate loading the form with whatever it was that was used to generate the form input which made the page error - in the above example the form field name is not email but is email[$acunetix], which seems to have broken the page when it tries to process the form.
However, I don't know what was done to do that. The same IP address spent about 40 minutes forcing all kinds of stuff onto my pages which eventually crashed my site requiring a server reboot.
I realise that is down to me not writing robust enough code - but - I wondered how I can replicate sending the form data shown above to the page, as I'm stuck trying to work out how to do that.

Form is not created inside while loop

I am newbie to asp.net . I learned that only one server side form could be used on a page. So.. due to functional requirement I have to create multiple forms . I did it with normal forms (without runat="server" tag . I used while loop to create form. Counter is initialized to zero & incremented to a particular length. But after running page I found by viewing source on browser that first form tag was not there (that is made on counter value 0) and other forms were there (counter value greater than zero). For reference I am including my code
<%
int length = 0;
while (postListLength > length)
{ %>
<div class="View-Posts">
<div class="View-Post-Content">
<%=postList[length].PostContent %><br />
<form method="post" action="CompletePost.aspx">
<input type="hidden" name="RequestedId" value="<%=postList[length].PostId.ToString()%>" />
<input type="submit" value="See More" />
</form>
</div>
</div>
<%
length++;
}
%>
Then I made another asp page without loop only one form there also I got the same problem.
But the inner content of form is there like textbox etc. only form tag is not there for first form
Any help will be appreciable

form verification before submitting

I have following form
<form id="myForm" action="/Problems/Post" method="post" enctype="multipart/form-data">
<input type="text" id="problemSubject" name="problemSubject" />
<input type="file" id="uploadFile" name="uploadFile"/>
<textarea rows="" cols="" class="form-textarea" id="problemDescription" name="problemDescription"></textarea>
</form>
I have to submit form to controller method(which i have done), but it should be first validated i.e. it should not contain empty fields. What i want is that "a message should appear telling that field is blank". How this can be done. Please help me. Thanks.
Take a look at some of the samples. (http://www.asp.net/mvc/tutorials/older-versions/javascript/creating-a-mvc-3-application-with-razor-and-unobtrusive-javascript)
Essentially you can validate on client side and on server side, which you should do both.
It is very easy to do validation in asp.net mvc3. Look at some tutorials like above.
Or this one: http://www.codeproject.com/Articles/249452/ASP-NET-MVC3-Validation-Basic
u can use server side validation controls...
plz hv a look [link]http://msdn.microsoft.com/en-us/library/aa479013.aspx
or use the jquery gven below--->
function callOnload(){
if($('#problemSubject').val() == '')
alert('fill the values');
if($('#uploadFile').val() == '')
alert('fill the values');
}

ASP (VBscript) radio buttons not returning value

I have 2 very simple pages, an HTML page and a classic ASP page .. the html page has a form which calls (and sends) the data to the ASP form (which then prints out the data)
The problem is I'm not getting the value of the radio button, I'm simply just getting "on".
Here is the html:
<form action="form.asp" method="post">
<strong>Gender:</strong>
<input type="radio" value"male" name="gender">Man
<input type="radio" value"female" name="gender">Woman<p></p>
<strong>Size:</strong>
<input type="text" width="20" name="size" size="4"><p></p>
<strong>Color:</strong>
<select size="1" name="color">
<option>blue</option>
<option>green</option>
<option>black</option>
</select><p></p>
<input type="submit" value="Send Order">
</form>
and here is the ASP
<%
Dim strgen, strsize, strcol
strgen = Request.form("gender")
intsize = Request.form("size")
strcol = Request.form("color")
Response.write "Your gender: " & strgen & "<br />"
Response.write "Your size: " & intsize & "<br />"
Response.write "The color you ordered: " & strcol & "<br />"
%>
Like I said, all I'm getting for "strgen" is "on" ...
There's typos in your code, missing equals sign.
value"male"
should be
value="male"
Because the value was ignored it was returning the default value of "on"
Try using an html validator as www.htmlvalidator.com. This site offers a free one which is good (I'm using the professional version myself).
This will find such types immediatly (and will save you countless hours of searching).

Best way to implement Google Custom Search on an aspx page

Google custom search code is provided as a form tag. However, Asp.net only allows a single form tag on a page. What is the best way to implement their code so you can include it on an aspx page (say as part of a Masterpage or navigation element).
You can have multiple form tags on an ASP.NET page. The limitation is on server-side (runat="server") form tags.
You can implement two form tags (or more) as long as only one has the runat="server" attribute and one is not contained in the other. Example:
<body>
<form action="http://www.google.com/cse" id="cse-search-box"> ... </form>
<form runat="server" id="aspNetform"> ... </form>
<body>
You may be able to have multiple form tags, but note that they cannot be nested. You'll run into all kinds of weirdness in that scenario (e.g., I've seen cases where the opening tag for the nested form apparently gets ignored and then its closing tag winds up closing the "parent" form out).
You'll need to remove the form tag and use javascript send the query. Have a look at
http://my6solutions.com/post/2009/04/19/Fixing-Google-Custom-Search-nested-form-tags-in-asp-net-pages.aspx
I have included the before and after code as well. So you can see what I've done to integrate it with blogengine .net.
You could use Javascript:
<input name="Query" type="text" class="searchField" id="Query" value="Search" size="15" onfocus="if(this.value == 'Search') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Search'; }" onkeydown="var event = event || window.event; var key = event.which || event.keyCode; if(key==13) window.open('http://www.google.com/search?q=' + getElementById('Query').value ); " /><input name="" type="button" class="searchButton" value="go" onclick="window.open('http://www.google.com/search?q=' + getElementById('Query').value );" />

Resources