开发者

Use asp.net button with a html form

I got a request to add this form to a asp.net control.

I want to use asp.net text box and button to submit the info to the form. (because I have special controls to match the look and feel).

this is the form:

<form name="ccoptin" id="signup" action="http://visitor.r20.constantcontact.com/d.jsp"
target="_blank" method="post">
<input type="hidden" name="llr" value="yyyyyy">
<input type="hidden" name="m" value="xxxxxx">
<input type="hidden" name="p" value="oi">
<label>sign up for new services and promotions:</label>
<input type="text"name="ea" value="" class="text" /> 
<input type="submit" id="ifr开发者_如何学Pythoname" class="submit"
 name="go" value="submit" />
 </form>

can this be done?


yes, you can use asp.net Textbox control for html input control and you can put the same styling. e.g.

 <asp:TextBox ID="ea" CssClass="text" runat="server"></asp:TextBox>

Button control for html submit button e.g.

 <asp:Button ID="iframe" CssClass="submit" runat="server" Text="submit" />

For your input type hidden, you can use asp.net HiddenField Control

<asp:HiddenField ID="llr" runat="server" Value="yyyyyy" />


Yes it can be done . On browser side ASP.NET controls get converted in to HTML even if you use the asp.net button.

Drag and drop asp.net button from toolbox and put attribute id , cssclass , name , text . It will get converted in end to HTML as expected

<asp:Button id="iframe" cssclass="submit"
  Text="Submit" runat="server" />


Yeah. You have to consider these notes:

  1. If you want to use ASP.NET controls, you should add runat='server' attribute to your form element. It's because ASP.NET controls (AKA server controls) while rendering check to see if they are get rendered in a server form (VerifyRenderingInServerForm method).
  2. <asp:Hidden control is your replacement for <input type='hidden'
  3. <asp:TextBox control is your replacement for <input type='text'
  4. <asp:Button control is your replacement for <input type='submit'
  5. All of your server controls should have runat='server' attribute


ASP.NET only allows for one form with runat=server, and all of your server controls have to be within a form with runat=server. Nesting forms isn't advisable.

See reference on form nesting: https://web.archive.org/web/20170420110433/http://anderwald.info/internet/nesting-form-tags-in-xhtml/.

You'll need the form in a different document object - maybe host it in an iframe and conver the mini-form to an ASPX page that you load into the iframe ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜