4 Replies - 1332 Views - Last Post: 25 May 2017 - 02:19 PM

#1 wtp  Icon User is offline

  • D.I.C Regular

Reputation: 26
  • View blog
  • Posts: 319
  • Joined: 08-December 11

WebForms - single page - multiple REST calls

Posted 25 May 2017 - 11:32 AM

Only one of web forums, poorly developed, <form> tags are allowed on a single page. Textboxes must be in form tag. I want to perform REST calls from user input on a single page. What's the best way to do this?
Is This A Good Question/Topic? 0
  • +

Replies To: WebForms - single page - multiple REST calls

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5061
  • View blog
  • Posts: 13,656
  • Joined: 18-April 07

Re: WebForms - single page - multiple REST calls

Posted 25 May 2017 - 11:42 AM

You can certainly make asynchronous calls. I just got done with a project that did just that. You can start by making the <%@Page%> directive specify an attribute of Async="true" and then in the code behind you can start writing functions and such which are using the async/await syntax. Event handlers can be defined as async void and you can make calls to Task handling functions.

In these functions you can do things like HttpClient.GetAsync, PostAsync etc all through the HttpClient class. It is a rather nice class to work with and you can do everything you need to support making REST calls.

More information can be found at the following link which talks about it more...

https://docs.microso...ds-in-aspnet-45

Hope this helps you out! :)
Was This Post Helpful? 2
  • +
  • -

#3 wtp  Icon User is offline

  • D.I.C Regular

Reputation: 26
  • View blog
  • Posts: 319
  • Joined: 08-December 11

Re: WebForms - single page - multiple REST calls

Posted 25 May 2017 - 12:20 PM

I don't want to make asynchronous calls. The resource you posted shows how to make multiple REST calls on a single page, but the calls don't take user input. I want to have a single page be able to make 2 synchronous rest calls. For example a page with 2 textboxes and 2 buttons. When I click the button1 it takes the text from textbox1 and POSTs it. When I click button2 it takes text from textbox2 and POSTs it.

The issue with this is that TextBoxes must be in a Form tag, and there can only be one Form tag.

    <div>   //I can't put a form tag around here since there is already a form tag below
            //This asp:TextBox will throw an error because it's not in a form tag
            <asp:TextBox ID="textbox1" runat="server"></asp:TextBox>
            <asp:Button ID="button1" runat="server" Text="Do POST1" />
            <asp:Label ID="result1" runat="server"></asp:Label>
    </div>

    <div>
        <form id="form1" runat="server">
            <asp:TextBox ID="textbox2" runat="server"></asp:TextBox>
            <asp:Button ID="button2" runat="server" Text="Do POST2" />
            <asp:Label ID="result2" runat="server"></asp:Label>
        </form>
    </div>


Update I found a solution:
Put the form tag around everything. You can then choose which textboxes you want to grab values from.

 <form id="form1" runat="server">
    <div>   //I can't put a form tag around here since there is already a form tag below
            //This asp:TextBox will throw an error because it's not in a form tag
            <asp:TextBox ID="textbox1" runat="server"></asp:TextBox>
            <asp:Button ID="button1" runat="server" Text="Do POST1" />
            <asp:Label ID="result1" runat="server"></asp:Label>
    </div>

    <div>
       
            <asp:TextBox ID="textbox2" runat="server"></asp:TextBox>
            <asp:Button ID="button2" runat="server" Text="Do POST2" />
            <asp:Label ID="result2" runat="server"></asp:Label>
        
    </div>
</form>

This post has been edited by wtp: 25 May 2017 - 01:23 PM

Was This Post Helpful? 0
  • +
  • -

#4 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5061
  • View blog
  • Posts: 13,656
  • Joined: 18-April 07

Re: WebForms - single page - multiple REST calls

Posted 25 May 2017 - 02:15 PM

Glad you found something that works. I would suggest you do consider the asynchronous solution though because that will only speed up your page. Otherwise if one of your REST calls takes too long to return, your page is hung up and unresponsive. It just leads to a bad experience. The more calls you make too the more chance it can get hung up.

:)
Was This Post Helpful? 1
  • +
  • -

#5 wtp  Icon User is offline

  • D.I.C Regular

Reputation: 26
  • View blog
  • Posts: 319
  • Joined: 08-December 11

Re: WebForms - single page - multiple REST calls

Posted 25 May 2017 - 02:19 PM

Thanks for the advice :tank:/>

This post has been edited by wtp: 25 May 2017 - 02:20 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1