<html>
<body>
<%# Language=VBScript ENABLESESSIONSTATE = False%>
<form Name="sushant" method="post" action="sushant.asp">
<select id="selFiles" name="selFiles" class="Select" style="width: 250px" tabindex="130">
<%
Dim fso, folder, files
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set folder=fso.GetFolder("C:\")
Set files=folder.Files
For each folderIdx In files
Response.Write("<option>" + folderIdx.Name + "</option>")
Next
%>
</select>
</body>
</html>
i am trying this code by giving its link in another file. but on execution IE shows an error in line set fso=Server.createobject..... i am trying but i could not locate the error. can anyone help me out. sorry for the formatting issue.
Generally, you'll get that error if the system cant find the registerd object. Give
regsvr32 %windir%\system32\scrrun.dll
a go, and see if it sorts you out.
I've also seen the problem,specifically with the FSO, on a server with AV software that seemed to block it, so check this out too.
Related
Questions about this do exist on stack but the answers are either wrong or of little use.
Coming from older VB, and being familiar with Java (where the code runs fine on client), trying to populate a textbox server side asp is driving me up the wall. Microsoft's logic is simply inane (regardless of topic).
Yes, it's probably due to a lack of conceptualization on my part, but if the textbox has an id and I can pull data, why can't I write to a different textbox with a named id?
I can write to the body, so why not a text box with a named id? It makes no sense to me. Is there some issue with just text boxes?
Any feedback, esp with a tech explanation of what I fail to understand, would be greatly appreciated.
Very simple code example:
<!DOCTYPE html>
<html><body>
<form action="p3.asp" method="post">
AnyVal: <input type="text" name="AnyVal" size="20" />
Other: <input type="text" name="Other" size="20" />
<input type="submit" value="Submit" />
</form>
<%
dim sRet
sRet=Request.Form("AnyVal")
If sRet <> "" Then
Response.Write("Your Val is: " & sret & "!<br>")
Other.value=sRet
End If
%>
</body></html>
Yes, it's probably due to a lack of conceptualization on my part,
I agree with that statement, you simply can't do that ... let me explain it simple taking an extract of recent answer i wrote in the past days
vbscript dropdown in function without using HTML (classic ASP)
classic-asp like almost every other preprocessor languages for web
applications, doesn't have the faculty to interact directly with your
browser. instead the language provides you a set of methods to write
and recieve data from the user-agent (not necesarry a browser).
and the browser relies on HTML,XHTML,CSS and derivatives to construct
an interface to the user, and due to fact that preprocessor doesn't
interact directly with HTML, that its the reason because you can't
make a dropdown in pure vbscript bypassing HTML code.
What are you trying to do is to treat your form elements as objects using ASP language, unfortunately you can't do that because the form elements are not visible to server preprocessor (ASP).
You need to write code to actually on the HTML, because such form elements doesn't exists to the ASP engine
<%
dim sRet
sRet=Request.Form("AnyVal")
If sRet <> "" Then
Response.Write("Your Val is: " & sret & "!<br>")
End If
%>
<!DOCTYPE html>
<html><body>
<form action="p3.asp" method="post">
AnyVal: <input type="text" value="<%=sRet%>" name="AnyVal" size="20" />
Other: <input type="text" value"<%=sRet%>" name="Other" size="20" />
<input type="submit" value="Submit" />
</form>
</body></html>
I hope I'm being clear in my explanation about how really ASP works
Looking at your code I think the easiest way to achieve what you want is the following.
<%
dim sRet
sRet=Request.Form("AnyVal")
%>
<!DOCTYPE html>
<html><body>
<form action="p3.asp" method="post">
AnyVal: <input type="text" name="AnyVal" size="20" />
Other: <input type="text" name="Other" size="20" value="<%= Sret %>" />
<input type="submit" value="Submit" />
<%
If sRet <> "" Then
Response.Write("Your Val is: " & sret & "!<br>")
End If
%>
</form>
</body></html>
Your Classic ASP is server side code and your form elements are client side, so they can't interact with each other.
NB You've tagged this as Classic ASP. If you mean ASP.net then you need to use a server side control - <asp:Textbox> Note that VB and VBScript are different, just as Java and JavaScript are different
Edit - #Rafael beat me to posting this, and he gives a more detailed explanation of more or less the same, so you should probably accept his answer
Thank you for your kind replies, but I think I got it nailed.
I'll post the code below, in case others may find it useful.
I kinda knew that asp & java interact with html differently, but one of the things that threw me was using a javascript variable to get the server side variable.
for example,
var cret;
cret = <%= sret %>
which works if is sret is a number but not if it's a string (don't know why, perhaps someone could enlighten me).
I did figure out getting asp to generate a text box on the fly and populate it.
But, I really wanted the javasript on the client side to do this part. From a practical point of view, I could have just given up and let asp do it, but I became a bit ocb about the whole thing.
I've read a lot of postings, blogs, etc. about this issue. It seemed to me that the proposed solutions were either convoluted of just didn't work. The question seems to get asked a lot, so I was surprised to find no fairly straightforward answer.
Everything I wanted to do could have been done in javascript, even using runat=server. But I specifically wanted to keep some of the code behind the page private. afaik, this needed asp.
I suspect that this is the main reason other want to populate elements via javascript whicle still using asp on the server.
The following code uses a form post, where asp can do some manipulation and generate an input element which can be subseqently accessed/manipulated by javascript. For this example the input element is hidden.
<!DOCTYPE html>
<html><head>
<title>asp java test</title>
</head>
<body>
<form action="p5.asp" method="post">
<p>Paste into the yellow box and then click Go.</p>
Set Val:
<input type="text" id="setval" name="setval" size="30"
style="background-color: #FFFFCC" />
<input type="submit" value="Submit" /><p>
Ret Val:
<input type="text" id="retval" name="retval" size="30" />
</form>
<!-- Server Side -->
<%
dim sret
sret = Request.Form("setval")
If sret = "" Then sret = " Nada"
// <!-- gen output server side-->
response.write("<input type='hidden' id='hid1' name='hid1' value='" & sret & "'/><br>")
%>
<!-- Client Side -->
<script language = "JavaScript">
var cret;
{
// Get the val
cret = document.getElementById("hid1").value;
// Populate the output box
document.getElementById("retval").value = cret;
}
</script>
</body></html>
Seems to work quite well for it's intended purpose.
Gary
Ok Good afternoon.
I'm Just starting ASP.
in php i do something like this
<?php
If(isset($_POST["submit"]))
{
echo "You clicked me yeh?";
}
?>
Works without problems , Now i try to translate the same for ASP and i do something like this
<html>
<head>
<title>testHome in ASP</title>
<body>
<%
if Request.Form("submit") ="test" then
Response.Write("Ok Mate You Just Clicked Me!")
%>
<form name = "superform" id="superform" method="post" action="idc.asp">
<input type="submit" name="submit" value="test"/>
</form>
</body>
</head>
</html>
And instead i get this super annoying error.
An error occurred on the server when processing the URL. Please contact the system administrator.
If you are the system administrator please click here to find out more about this error.
Please What Seems to be the error here?
You need to close off the 'if ... then'
end if
If you can, you can get IIS to send error messages to the browser: IIS6 or IIS7
And if you are using visual studio you can also setup debugging
This feels like a very stupid question, but I've been trying and searching for hours and can't figure out the problem. I'm new to pretty much all web development, and this was a test to figure out how to access form data on a new page. It just will not work for me. I have contactus.html and contactusaction.asp saved in the same folder on my desktop. Clicking submit loads contactusaction.asp, but "fname" will not appear on the next page no matter what I try. I've even copy and pasted other people's request.form examples, and I still have yet to get the comand to work in any way.
contactus.html:
<html>
<head>
Hello
</head>
<body>
<form method="post" action="contactusaction.asp"/>
<input type="text" name="fname"/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
contactusaction.asp:
<html>
<head>Hello:</head>
<body>
<%
Dim x
x=Request.Form("fname")
Response.Write(x)
%>
</body>
</html>
Silly question, but after reading "saved in the same folder on my desktop" I have to ask - are you testing this using IIS or some other web server software on your desktop?
If you're just opening the local HTML page directly (double-clicking on the file vs running a local IIS and going to http://localhost/ or however you have it set up), there's no server running the actual ASP/VBScript code.
Also, reguardless of the answer to the above question, you should definitely fix the <form> tag as Guido Gautier mentions in his comment to your question.
This:
<form method="post" action="contactusaction.asp"/>
Should be this:
<form method="post" action="contactusaction.asp">
I have been told I will be let go at the end of the week if I can't figure this out by the end of the day. I need help in figuring out this issue. I am trying to create a .aspx page for a sharepoint site. This is the code I have...
<script runat="server">
Sub submit(Source As Object, e As EventArgs)
button1.Text="You clicked me!"
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit" />
</form>
</body>
</html>
I keep getting error messages every time I load the page. I ripped this code off the internet and when I load the page it says:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Code blocks are not allowed in this file.
Source Error:
Line 3: button1.Text="You clicked me!"
Line 4: End Sub
Line 5: </script>
Line 6:
Line 7: <!DOCTYPE html>
Please help me. Why am I getting this message?
SharePoint doesn't allow inline code in .aspx files by default. You'll need to change that setting in the web.config if you want to do this, but it's not recommended. See the link #Mark posted in the comments.
As an alternative, you can create a webpart, and add that to the page. See this article for more help on how to do this.
You can allow adding code inside sharepoint pages by adding below lines in the web.config file
<PageParserPaths>
<PageParserPath VirtualPath="/pages/test.aspx" CompilationMode="Always" AllowServerSideScript="true" />
</PageParserPaths>
Where "/pages/test.aspx" is the path of your page , or you can add it as "/_catalogs/masterpage/*" for example to add all masterpages files.
I have some code in my master page that sets up a a hyperlink with some context sensitive information
<%If Not IsNothing(Profile.ClientID) Then%>
<span class="menu-nav">
<a target="_blank"
href=
"http://b/x.aspx?ClientID=<%=Profile.ClientID.ToString()%>&Initials=<%=Session("Initials")%>"
>
Send
<br />
SMS
<br />
</a>
</span>
<%End If %>
<span class="menu-nav"> <!-- Name __o is not declared Error is flagged here-->
Now the issue seems to be in the href part. If I remove the dynamic code the error disappears. Can anyone tell me how to resolve this issue?
I've found the answer on the .net forums. It contains a good explanation of why ASP.Net is acting the way it is:
We have finally obtained reliable repro and identified the underlying issue. A trivial repro looks like this:
<% if (true) { %>
<%=1%>
<% } %>
<%=2%>
In order to provide intellisense in <%= %> blocks at design time, ASP.NET generates assignment to a temporary __o variable and language (VB or C#) then provide the intellisense for the variable. That is done when page compiler sees the first <%= ... %> block. But here, the block is inside the if, so after the if closes, the variable goes out of scope. We end up generating something like this:
if (true) {
object #__o;
#__o = 1;
}
#__o = 2;
The workaround is to add a dummy expression early in the page. E.g. <%="" %>. This will not render anything, and it will make sure that __o is declared top level in the Render method, before any potential ‘if’ (or other scoping) statement.
An alternative solution is to simply use
<% response.write(var) %>
instead of
<%= var %>
Yes, I have experienced the same bug occasionally in pages that use server side constructs on ASPX pages.
Overtime, I found a fix for it (I'm sorry, I just haven't been able to find out where I found this bit of info again.) and that fix is to put the following code above the errant <%...%> block:
<%-- For other devs: Do not remove below line. --%>
<%="" %>
<%-- For other devs: Do not remove above line. --%>
Apparently, where you put the above code makes all the difference to VS.NET, so it may take a few tries to get it right.
This is an odd solution, but for me I managed to fix this problem by simply closing the offending open files in Visual Studio.
With them open, i was erratically getting the __o problem.
As soon as I closed them, the __o problem disappeared.
After some hours of googling and analyzing bunch of aspx'ses in my current project seems I've found the solution, that is working for me. Would to advise strongly avoid html-style comments:
<!-- ... -->
inside aspx page. Instead of it use aspx-style comments
<%-- ... --%>
Additionally it helped me obtain that vs intellisense and code highlighting became working again and the mainly thing - this case had begun from it - vs can now hit the breakpoints inside embedded pieces of vb/cs code! And no any damn "This is not a valid location for a breakpoint" message.
When I've cleaned the solution, restarted IIS and it is still mysteriously playing up, I find this can sometimes be caused by pasting an ASPX source file's contents from another system into Visual Studio which "helpfully" updates the code, possibly changing some IDs and breaking the page.
Pasting it into another editor (Notepad++?) then saving it stops Visual Studio from "being helpful" and the page works again.