html method=get not passing values to the next aspx page - html

i have simple html page with 3 textboxes.
<form id="form1" method=get action="http://mysite.com/default.aspx" runat="server">
<div>
<input id="name" type="text" value="Amy" />
<input id="email" type="text" value="amy#jf.com"/>
<input id="phone" type="text" value="2125552512" />
</div>
<input id="Submit1" type="submit" value="submit" />
</form>
Now when it loads default.aspx i have this code in the vb backend on page_load.
Dim tbName As TextBox = Page.FindControl("Name")
Dim tbPhone As TextBox = Page.FindControl("Phone")
Dim tbEmail As TextBox = Page.FindControl("Email")
If page.request("name") & "" <> "" AndAlso tbname IsNot Nothing Then
tbname.text = page.request("name")
End If
If page.request("email") & "" <> "" AndAlso tbEmail IsNot Nothing Then
tbEmail.text = page.request("email") & ""
end If
If page.request("phone") & "" <> "" AndAlso tbphone IsNot Nothing Then
tbPhone.text = page.request("phone") & ""
End If
The page loads but is these textboxes are empty. what am i doing wrong?

If you want to be able to access those controls serverside, you'll need to add the runat="server" attribute to each of them.
Also, the TextBox type you're referencing is the ASP.NET control, which you aren't using. What you'd be using, once you add the runat="server" tags is HtmlInputText.
You can use the TextBox type by using the TextBox ASP.NET control instead of the <input> elements:
<asp:TextBox ID="name" runat="server" Value="Amy" />
If all your ASP.NET page is doing is processing the request from the form, then there's no need to reference any textbox or input controls - it won't be possible since they don't exist as ASP.NET controls. All you need to do is read the values from Request.QueryString.
If the intent is for the inputs to be visible and/or editable once they're on the ASP.NET page, I'd recommend moving the HTML form into your ASP.NET page.

it is not like this that webform functionate.
First, your input in your form needs to be server control: ex <asp:TextBox runat="server" id="name" Text="value" />
Then in your codebehind file you do not have to go through Page.FindControl("YourInput") but only this.YourInput.Text

Related

Can't set radio button checked value with webbrowser control

I'm having trouble setting a radio button via a webbrowser control in VB.NET. This is the HTML code I'm trying to act upon:
<td align="right">
Afficher statuts :
</td>
<td>
<label for="Company">
<input type="radio" id="Services" value="true" name="requestinfo_0" />
Company
</label>
<label for="Partener">
<input type="radio" id="Workload" value="false" name="requestinfo_0" />
Partener
</label>
<label for="All">
<input type="radio" id="All" value="" name="requestinfo_0" />
All
</label>
The solution I found from searching shows it should work like this, but it doesn't!
WebBrowser1.Document.GetElementById("Workload").SetAttribute("Checked", True)
But I believe I would need to specify the name as well as from what I can tell it's possible to have more than 1 ID as "Workload" but in a radio button with a different name. But I can't see where or how to write the code accordingly.
I'm doing this in Visual Studio 2019 in Visual Basic.
You must to do that after your WebBrowser have finished to load the document. A little example below:
WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Navigate("https://html.com/input-type-checkbox/")
AddHandler WebBrowser1.DocumentCompleted, Sub(senderObj As Object, eObj As WebBrowserDocumentCompletedEventArgs)
Dim love As HtmlElement = WebBrowser1.Document.GetElementById("love")
If love IsNot Nothing Then
love.SetAttribute("checked", "checked")
End If
End Sub
Solved the problem by using a click event! Works fine now!
For Each curElement As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
If curElement.GetAttribute("type") = "radio" AndAlso curElement.GetAttribute("id") = "Services" Then
curElement.SetAttribute("checked", "checked")
End If
If curElement.GetAttribute("type") = "radio" AndAlso curElement.GetAttribute("id") = "Radio3" Then
curElement.SetAttribute("checked", "checked")
End If
If curElement.GetAttribute("type") = "radio" AndAlso curElement.GetAttribute("id") = "all" Then
curElement.SetAttribute("checked", "checked")
End If
Next
Pete

Trying to fill in a form to login to a site via VBA but wont register the text I've entered

First time poster, long time user.
I'm trying to write a script in VBA to login to a site to then extract data at a later step.
I've hit a road block with trying to logon to the site, there is three classes that change once you manually fill in the username and password and two aria-invalid that turn from true to false. Unfortunately, this doesn't update if you try and fill in the forms via VBA.
This is the VBA code I currently have
Option Explicit
Sub LoginToSite()
Dim IE As New SHDocVw.InternetExplorer
IE.Visible = True
IE.navigate "https://website.com.au"
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
IE.Document.forms("form").elements("username").Value = "FredFlinstone"
IE.Document.forms("form").elements("password").Value = "Password000"
IE.Document.forms("form").elements("submit-button").Click
End Sub
This is the HTML before manual text is added into the forms:
`<form name="form" class="login-form ng-pristine ng-invalid ng-invalid-required" novalidate="" autocomplete="off">
<div class="field-container">
<label for="username">
Username
</label>
<input name="username" class="ng-pristine ng-empty ng-invalid ng-invalid-required ng-touched" id="username" aria-invalid="true" required="" type="text" ng-keydown="vm.loginOnKeyEnter($event)" ng-class="vm.usernameEmptyClass" ng-model="vm.username">
</div>
<div class="field-container ">
<label for="password">
Password
</label>
<input name="password" class="ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required" id="password" aria-invalid="true" required="" type="password" ng-keydown="vm.loginOnKeyEnter($event)" ng-class="vm.passwordEmptyClass" ng-model="vm.password">`
These are the parts that change in the HTML if you manually add text.
Form div
<form name="form"
class="login-form ng-dirty ng-valid-parse ng-valid ng-valid-required"
novalidate=""
autocomplete="off">
Username Div
<input name="username"
class="ng-touched ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required"
id="username"
aria-invalid="false"
required=""
type="text"
ng-keydown="vm.loginOnKeyEnter($event)"
ng-class="vm.usernameEmptyClass"
ng-model="vm.username">
Password Div
<input name="password"
class="ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched"
id="password"
aria-invalid="false"
required=""
type="password"
ng-keydown="vm.loginOnKeyEnter($event)"
ng-class="vm.passwordEmptyClass"
ng-model="vm.password">
Very keen to learn what I need to change in order to trigger the site into realising there is text within the boxes to be able to login.
I've still got my L plates on with VBA, so code will most definitely not be the most efficient code, but keen to hear of better methods to executing the above
Thanks in advance Mr Swan
Try to use the .Focus method to focus the TextBox first, then use the SendKeys statement to enter the value.
The below code should work if it's single page but you'll have to fill out the SignIn Div information portion since this doesn't appear to be a valid URL. Just follow the same format and note that everything is case sensitive. TKs.
Sub LoginToSite()
Const cURL = "https://website.com.au"
Const cusername = "FredFlinstone"
Const cpassword = "Password000"
Dim IE As InternetExplorer
Dim doc As HTMLDocument
Dim LoginForm As HTMLFormElement
Dim UsernameInputBox As HTMLInputElement
Dim PasswordInputBox As HTMLInputElement
Dim SigninButton As HTMLInputButtonElement
Set IE = New InternetExplorer
IE.Visible = True
IE.navigate cURL
'Wait for initial page to load
Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
Set doc = IE.document
'Get the only form on the page
Set LoginForm = doc.forms(0)
'Get the Username textbox and populate it
'input name="username" id="username" size="18" value="" class="ng-touched ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required" type="text"
Set UsernameInputBox = doc.getElementById("username")
UsernameInputBox.Value = cusername
'Get the Password textbox and populate it
'input name="password" id="password" size="18" class="ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched" type="text"
Set PasswordInputBox = doc.getElementById("password")
PasswordInputBox.Value = cpassword
'Get the form input button and click it
'button class="XXXXX" name="XXXXX" id="XXXXX" value="XXXXX" type="text"
Set SigninButton = doc.getElementById("XXXXX")
SigninButton.Click
'Wait for the new page to load
Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
End Sub
Is everything on one page or is it split between two pages like the Gmail login?
1 page example: enter username, enter password, click login
2 page example: enter username (click next), enter password, click login

HTML, ASP - Contact Form Won't Work

This is my contact form that I want to connect to email upon form submission. I have researched on the net to do it but I cannot seem to run the codes.
I have two files where one is the html codes and another consists of the asp codes.
Need help on this please. Will appreciate your guidance.
<body>
<h3>Contact Form</h3>
<form name="form1" method="post" action="process.asp">
<label for="name">name</label>
<input type="text" id="name" name="name" placeholder="Your web id.."/>
<br><br>
<label for="deptID">Department ID</label>
<input type="text" id="deptID" name="departmentID" placeholder="Your department ID..">
<br><br>
<label for="issue">Issue</label>
<select id="issue" name="issue">
<option value="">Non-Availability of Test Points</option>
<option value="">Unable to Change Cycle Time Value</option>
<option value="">Unable to Retrieve Report</option>
</select>
<br><br>
<label for="subject">Additional Message</label>
<textarea id="subject" name="subject" placeholder="Write something.." style="height:200px"></textarea>
<br><br>
<input type="submit" value="Submit">
</form>
This is the process.asp page.
<%
formname = Request.Form("name")
formID = Request.Form("departmentID")
formquery = Request.Form("issue")
formsubject = Request.Form("subject")
Set Mail = Server.CreateObject("CDONTS.NewMail")
Mail.From = formname
Mail.FromName = formname
Mail.AddAddress "test#gmail.com"
Mail.Subject = "Form submitted from web site"
Bodytxt = "Details of Form submission :" & VbCrLf & VbCrLf
Bodytxt = Bodytxt & "Contact Name : " & formname & VbCrLf
Bodytxt = Bodytxt & "ID : " & formID & VbCrLf
Bodytxt = Bodytxt & "Query Entered : " & formquery & VbCrLf
Bodytxt = Bodytxt & "Subject Entered : " & formsubject
Mail.Body = Bodytxt
Mail.Username = "me#gmail.com"
Mail.Password = "password"
Mail.Host = "smtp.gmail.com"
Mail.Port = "587"
Mail.Send
Set Mail = Nothing
%>
Not sure whats going on with your code snippets but they look extremely incomplete, you need a heap more than that to join an ASP page to a backend set of code.
A standard setup using C# and ASP.Net is the following. Say my page is called "Default.aspx"
This would be my (As you called is HTML, but really you mean your ASP)
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
And then joined to this would be the C# ASP.Net
That would look something like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
What you have done above will never work, there is nothing referencing between the two files, your first piece of code is just plain html not ASP and there is nothing that defines your C# environment.
What I would suggest, get Visual Studio 2015 (Its free) and then click "New" and select ASP Website. Once you have done that click your new project and hit "Add Web Form" that will give you a good start, then you can start adding your form and code.
Caz

How to fill html input with random tag id and name in vb.net?

I'm trying to fill a html input box, but it won't fill, because i can't get the value of the tag name or id, because it changes every time the page is reloaded, here is the html code:
<input id="1b9b8d81-aead-4930-90de-4c20121bc2d6.loginForm.username" maxlength="50" name="1b9b8d81-aead-4930-90de-4c20121bc2d6:username" value="" tabindex="1" class="mail inpRad" type="text" crmwa_forminfo="e-mail|">
And here is what I tried to do in vb.net:
Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
For Each webpageelement As HtmlElement In allelements
If webpageelement.GetAttribute("value") = "mail inpRad" Then
webpageelement.SetAttribute("value", "loloolloolloollol")
End If
Next
It didn't work.. I need some clue to get it working.

How to get value of HTML element with VB.net

I create html element from database :
Dim table As String = "<form method='POST'>"
table &= "<input type='textbox' value='123' id='txtText'/>"
table &= "<input type="sumbit" text='Submit' /></form>"
When i click button submit, I want get value textbox with VB.NET
You just need to use RUNAT = "SERVER"
<form method='POST'>
<input type='textbox' value='123' id='txtText'/>
<input runat="SERVER" type="hidden" name="txtHidden" value="123" />
</form>
You need to set the value to hidden text, use runat = "SERVER"and get the value on server-side.