Invoke an Input on a form from an app

J

James

Hello everyone,
I am trying to pull information off of a Bus Transit website. They do not
have web services and have know plans too!

I would like to know:
1. how to run/start a click event on an Input button
2. and also is it possible to trap the page being returned - currently
if I click the button manually it opens up a browser with the new page.

Below is the code I am using. I can update the info I need to, but cannot
fire the click event on the submit button. Also, getting the returning page
into WB1 would be needed also.

-JD




Here is the page I load into a WebBrowser control:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bntFetch.Click
wb1.Url = New
Uri("http://www.edmonton.ca/portal/server.pt?space=CommunityPage&control=SetCommunity&CommunityID=239")
End Sub

From there I can find all the info I need:

Private Sub btnParsePage_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnParsePage.Click

Dim htmlDoc As System.Windows.Forms.HtmlDocument = wb1.Document
Dim htmlDocColl As System.Windows.Forms.HtmlElementCollection =
htmlDoc.Forms("frmBusStopScheduleForm").All

For Each El As System.Windows.Forms.HtmlElement In htmlDocColl
If El.Name.Trim = "" Then
Else

'This is the bus stop I want info for
If El.Name.Trim = "txtBusStopNumber" Then
El.InnerText = "5551"
End If

'This is the button to click to get the bus stop info
If El.Name.Trim = "cmdBusStopScheduleSubmit" Then

'this does not work?!
El.InvokeMember("cmdBusStopScheduleSubmit.onclick")

End If

lstDocEles.Items.Add(El.Name.ToString)

End If

Next
End Sub
 
J

James

Hello all,
Have an update; have changed my InvokeMember to read:

'this runs, If I leave the form untouched an "alert" is run.
If El.InvokeMember("onclick") Then
lstCMD.Items.Add("true")
Else
lstCMD.Items.Add("false")
End If

The function in question seems to fire. When I set the txtBusStopNumber to
nothing I get the validation error message to appear.

'This is the bus stop I want info for
If El.Name.Trim = "txtBusStopNumber" Then
El.InnerText = ""
End If

When I set the txtBusStopNumer field, (El.InnerText = "5551") I rec no
validation error but always get a false return - the form is not posted.

Here is the onclick event I am invoking, not the If
(ValidateBusStopSchedule()) function. Just below this script is the validate
function.

<TD>
<input type="submit" name="cmdBusStopScheduleSubmit" value="Get Bus Stop
Schedule" id="cmdBusStopScheduleSubmit" class="formBtnText"
onclick="if (ValidateBusStopSchedule())
{
gfnTransit_SwitchPostBackUrl('BusStopSchedule.aspx|BusStopLookup.aspx','BusStopSchedule_Results.aspx','frmBusStopScheduleForm','_blank','NOVIEWSTATE');
}
else {
return false;
}"
style="height:40px;width:155px;" /></TD>


This function sets blnValid to TRUE but it is always set to FALSE when I
invoke the above onclick event. I set txtbusstopnumber and leave all other
fields as they are as they are set to the current date and time - just like
I would surfing the form manually.
\
<SCRIPT language="javascript">
function ValidateBusStopSchedule()
{
var blnValid = true;
var strMessage = "";
//check that Form fields are populated and valid
if (document.forms['frmBusStopScheduleForm'].txtTravelDate.value =='')
strMessage = strMessage + "Please enter a valid date\n"
if (document.forms['frmBusStopScheduleForm'].txtBusStopNumber.value =='')
strMessage = strMessage + "Please enter a valid Bus Stop Number\n"
if (strMessage !='')
{
blnValid = false;
alert(strMessage)
}
return blnValid;

}
</SCRIPT>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top