classic asp - response.redirect and response.write problem - variables

The problem if someone types into the search box a location it goes through to that location page but if they type in a location thats not found or they dont type anything in I need it to redirect back to the homepage (index.asp) and display "whoops we couldnt find that" in the search box (input field)
This is the vb
Case Else
response.redirect "index.asp?whoops=whoops we couldnt find that"
End Select
Then in the value of the input field I have
value="<% =whoops %>"
This doesnt work by the way, first is this the best way of doing it because id rather not have the error message in the url. This there away of posting the error as a variable and then calling it into the input field like,
<% =whoops %>

You don't need the error message in the url. Also, whoops won't be available to you as a variable just because it is in the url. You have to look for it in the Request.Querystring collection. What you'd want to do is something more like this on the homepage:
Dim whoops : whoops = ""
If Request.Querystring("whoops") Then
whoops = "whoops we couldnt find that"
End If
Then you could output <%=whoops %> as the search box's HTML value attribute. This would also prevent people from being able to assign whatever they want to the value of whoops, which is a security vulnerability.

Related

Problem with active status when an continue form have zero record for a filter

this is my first question here and english isnt my language but I'll try to explain at my best.
Im using MS Access 2007.
The form is a "continue form" with a header section where you find an "apply filter" button and a field named "cmpCercaCognome" (italian language for "find surname" plus "cmp" in italian language as field).
This is a cut out of the feature where I am having problems.
The function is fine if the search filter that is set in the field produces at least one result.
The function fails if there are no results.
Private Sub cmpCercaCognome_Change()
If (ActiveControl.Name = "cmpCercaCognome") Then
LunghStr = Len(Me.cmpCercaCognome.Text)
else
LunghStr = Len(Me.cmpCercaCognome)
End if
'Something else but I dont reach it
end sub
The error appear when I'm clicking in the field "cmpCercaCognome" and then Im typing a key there to change the value to use for a filter that I'll apply with a button.
The check "activecontrol" is true still the Len function give error "2185 - Cant read control... without an active status..). How? I just check that have active status! And Im typing just there...
I tryed to modify the IF check so:
"If (ActiveControl.Name = "cmpCercaCognome") And (Me.RecordsetClone.RecordCount > 0) Then"
So I can check just when the count of the record is more than 0.
The problem that so I check the .value of the field that dont contain the last pressed key.
So isnt usefull for me
Is there any way to avoid the problem by keeping control of the temporary value of the field? Or is there a way to make the "temporary value" effective right away so as to avoid checking the .text property?
Thanks for any help you can get on this.

Unable to get the Query String value

Whenever I'm hitting this URL getting vToken is nothing. Please assist
Dim vHDR As String = Nothing
If Request.IsLocal Then
Dim vToken = Request.QueryString("approvalToken")
If Not vToken Is Nothing Then
Dim vUser = Helper.ValidateToken(vToken)
If Not vUser Is Nothing Then
vHDR = vUser
End If
End If
End If
URL:
http://localhost:56979/#/modules/Review?ID=20582&approvalToken=SIsJ3swuGjpPidOvWPSzuqfcTJH8IywIlVVEnkmIQU6yE93PUQ
In a URL, everything beginning with the hash sign (#) is called the Fragment Identifier. The fragment identifier section is the last section of the URL and comes after the url arguments.
So for this url from the question:
http://localhost:56979/#/modules/Review?ID=20582&approvalToken=SIsJ3swuGjpPidOvWPSzuqfcTJH8IywIlVVEnkmIQU6yE93PUQ
there is no query string. The section that looks like a query string was pre-empted to be part of a very long fragment identifier. Even the /modules/Review section that looks like part of the Path is actually part of the fragment.
I suspect somewhere in your base/index page you have a link with a blank href value, which is sometimes expressed with a single hash (#). You click that link, which puts the hash sign into the url:
http://localhost:56979/#
After clicking this link, you then redirect, click a new link, or do some other action that appends the relative url /modules/Review (which may already include the query string) to your current location. But now you have the hash sign as part of that existing location, and so you end up with the url in your question, which doesn't mean what you want it to mean.
I'd have to see a lot more code to tell you exactly how to fix this, but in the context of vb.net (asp.net), if this code runs on the server you probably want to change /modules/Review to ~/modules/Review. If this is done in javascript, I'd need to know more about your page.

Title of Message box not setting up

I am writing some code in Visual Basic 6. It also uses the Msgbox funtion. Now I searched this and I got to know that if you want to set the title of the Message box then this is the syntax:
Msgbox(<Prompt>,<Title>)
For example, I write this:
MsgBox ("Incorrect Answer!","QM")
It says:
Compile Error
Expected: =
Can someone tell me what is the problem?
With VB6, you can either request a response, and do something based on the answer, or you can simply display a message.
If you want to know what button was clicked, you need to use the function format - that is, you must use the brackets.
If you simply want to display a message, then you don't use the brackets.
So if you want to just display the message, then continue, do this:
MsgBox "Incorrect Answer!", , "QM"
But if you want to know which button the user clicked (e.g. to offer them a try again, cancel, then you need a variable, and you use the brackets to signifify that it's a function:
Dim response = MsgBox("Try again?", MsgBoxStyle.YesNo, "QM")
You can then look at the response variable to find out which button the user clicked.
A couple of pages for reference:
http://vb6reference.tomswebdesign.net/msgbox.html
https://msdn.microsoft.com/en-us/library/139z2azd(v=vs.90).aspx

How To Login on website? Password as value not accepted

I've looked at many examples on how to log in to a website using vb. But somehow it keeps saying the password is incorrect.
Let me explain:
I'm trying to log in to this website using vb. I have managed to fill in the username and the password using
wb1.Document.GetElementById("Username").SetAttribute("Value", "myusername")
wb1.Document.GetElementById("Password").SetAttribute("Value", "mypassword")
I can see them being filled in, but upon clicking on the login button it says the password in incorrect. When I try to fill in the password by hand (username by program) and click the button it does work.
The difference between the two instances? When I do it manually the letters I type become dots. But when I do it via my program the letters do not change but remain letters. I think this is part of the problem, but I'm not entirely sure.
I've tried to change other items as well such as OuterHTML from the element Password. I could see which items were adjusted when I manually entered the password. And then I used those values. This didn't work. But then again, it was hard to see what exactly changed, so maybe I missed something.
One thing I noticed while doing to was when I manually entered the password Value was changed to "". Should I put my password in a different attribute? I'm guessing the password should be send encoded to the server?
This is the code for the password field on the website
<div class="jNiceInputWrapper jNiceSafari FieldPosition col2">
<div class="jNiceInputInner">
<input type="password" name="Password" id="Password" class="jNiceInput" placeholder="Wachtwoord" onkeypress="return SubmitOnEnter(this,event)" />
</div>
</div>
I really hope someone can help me with this problem. I've been working on it all day and just can't figure it out.
EDIT:
Thanks to Mr CoDeXeR I finally figured it out!
The code that solved the problem:
wb1.Document.All("Username").SetAttribute("value", "myusername")
wb1.Document.All("Password").SetAttribute("value", "mypassword")
Dim elements As HtmlElementCollection = (wb1.Document.All.GetElementsByName("Password"))
For Each element As HtmlElement In elements
element.InnerText = "mypassword"
Next
Removing either the setattribute value or the innertext will lead to failure.
Try this, don't use GetElementsByID, use Document.All instead. You want to pass the element's name attribute value to all, you may be just missing some of them...
wB1.Document.All("Username").SetAttribute("value", Username)
wB1.Document.All("Password").SetAttribute("value", Password)
Let me know how this works out for you
EDIT
Upon looking at this more, we can't use the ways we tried since it's a masked input. Instead we can loop through the document and set the inner text of that element...
' Loop through elements until the element is found
Dim elements As HtmlElementCollection = wB1.Document.All.GetElementsByName("Password")
For Each element As HtmlElement In elements
element.InnerText = "your password"
Next

Visual Basic Web Browser change form when certain webpage content detected

I am trying to make a form on VB.NET that when a certain webpage is loaded into the web browser (in this case its a .txt file with a string of numbers). It will look for those numbers and if it finds them it will close that form and open another. I have tried to do it many times and my latest attempts came out with this code. Any help would be appreciated.
Dim passcontents As String
passcontents = WebBrowser.DocumentText = "test.com/test.txt"
If WebBrowser.DocumentText = "test.com/test.txt" And passcontents Then
ActualGen.Show()
Me.Close()
Else
End If
There are a couple of basic problems with the code you've posted.
1) Are you trying to test passcontents as a boolean or a string? You've defined it as a String, but then you are trying to assign the equality of two other strings to it, as you would a Boolean.
Try setting Option Strict On at the top of your code - it gives a few more helpful pointers to check in this case.
2) The If... Then condition is checking the same data as passcontents (may) already be providing. Are you just trying to check that the correct page is loaded, or do you want to check for certain page contents as well?
You appear to be getting mixed up between the browser's document URL and the loaded document contents.