Invoke an Input on a form from an app

Discussion in 'ASP .Net Web Controls' started by James, May 13, 2008.

  1. James

    James Guest

    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
    James, May 13, 2008
    #1
    1. Advertising

  2. James

    James Guest

    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>




    "James" <> wrote in message
    news:...
    > 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
    >
    >
    James, May 13, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg H
    Replies:
    1
    Views:
    428
    David Waz...
    Jul 3, 2003
  2. NGM
    Replies:
    0
    Views:
    2,291
  3. Curt_C [MVP]

    How to invoke second win form

    Curt_C [MVP], Jul 22, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    500
    Lupina
    Jul 23, 2004
  4. Replies:
    1
    Views:
    140
    Van den Driessche Willy
    Sep 20, 2006
  5. Replies:
    3
    Views:
    200
    desprateCoder
    Oct 13, 2006
Loading...

Share This Page