I need to post a form to a 3rd party URL in C#. The input fields must be named to match what the third party is expecting (in this case “Email Address”, etc). If I use a standard “input” tag I don’t have a great way to validate the control. If I use an “asp:TextBox” like in this example, it will rename my field and screw up my post. HELP!
<asp:TextBox id="CustomerEmailInput" runat="server"
name="Email Address"
CssClass="tb5a" >
</asp:TextBox>
<asp:RequiredFieldValidator ID="customerEmailRequired" runat="server"
ControlToValidate="CustomerEmailInput"
display="Dynamic"
ErrorMessage="*">
</asp:RequiredFieldValidator>
<asp:Button runat="server"
PostBackUrl="http://ThirdPartyUrl.com"
Text="Submit" />
So the above renders the following. I need the name to be “Email Address”, or I need a good way to validate the input field (this example is simplified, there are more fields and more regex validations).
<div>
<input type="text" name="ctl00$ContentPlaceHolder1$CustomerEmailInput" class="tb5a" id="ctl00_ContentPlaceHolder1_CustomerEmailInput">
<span style="color: Red; display: none;" id="ctl00_ContentPlaceHolder1_customerEmailRequired">*</span>
<input type="submit" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$ctl00", "", true, "", "http://thirdpartyurl.com", false, false))" value="Submit" name="ctl00$ContentPlaceHolder1$ctl00">
</div>
If you are posting straight from your form to the 3rd party without posting back to your server, then the simplest approach in traditional asp.net web forms would be to create your form, and then set it’s action to the third party URL explicitly and use plain old basic HTML with tags to introduce the content. Then, you introduce javascript to validate the fields on the client side.
If you post back to your server, and then post to the third party, it’s no problem whatsoever because then you can format your post any way you like.