Re: How to press a button programmatically...

Adam Tuliper <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <[email protected]>
http://forums.asp.net/p/1258291/2408979.aspx#2408979

(from page - not from me)
-------

One way to do this is to dynamically add hidden elements to the form with
the appropriate values and the fire the click event of a button on the
form.  Here is an example...

 Windows Form, trigger on some event:

       With Me.WebBrowser1.Document
           Dim one As HtmlElement = .CreateElement("input")
           one.SetAttribute("type", "hidden")
           one.SetAttribute("name", "one")
           one.Id = "one"
           one.SetAttribute("value", Now.ToString)
           .Forms(0).AppendChild(one)

           Dim two As HtmlElement = .CreateElement("input")
           two.SetAttribute("type", "text")
           two.SetAttribute("name", "two")
           two.Id = "two"
           two.SetAttribute("value", Now.AddDays(1).ToString)
           .Forms(0).AppendChild(two)

           .GetElementById("Button1").InvokeMember("click")
       End With


Web App:

   <form id="form1" runat="server">
   <div>
       <asp:Button ID="Button1" runat="server" Text="Button" /> <br />
       <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
       <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
       <br />
       <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
   </div>
   </form>

and

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
       If Request("one") IsNot Nothing Then Me.TextBox1.Text =
Request("one")
       If Request("two") IsNot Nothing Then Me.TextBox2.Text =
Request("two")
       Label1.Text = Now.ToString


 End Sub

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.