Post Back without runat="server" ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • z1freeride
    New Member
    • Feb 2009
    • 36

    Post Back without runat="server" ?

    I can't seem to get this form to Post Back:

    Code:
    <form action="test.aspx" method="post">
        <input type="text" id="blah" />
        <input type="submit" value="post" />
    </form>
    Page.IsPostBack returns false. Do I need runat="server" ? I have two forms on one page, so I can't use it on both of them.
    Last edited by Frinavale; Mar 23 '09, 08:06 PM. Reason: Moved to ASP.NET Answers from .NEt
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Are you using Visual Studio to create your application?

    Comment

    • z1freeride
      New Member
      • Feb 2009
      • 36

      #3
      Yes, I am. I'm thinking now of just sending the form data to a separate page now. But it would be nice to know if this is possible to do.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        In that case you should use the __doPostback('c ontrolID','') JavaScirpt method to raise a post back to the server.

        Your submit input should be an ASP.NET button....it will automatically cause the insert the __doPostback() JavaScript method for you....not only that but you will be able to retrieve the control's information on the server.

        So, what you should do is add an ASP.NET button to the page:
        Code:
        <asp:Button ID="theButton" runat="server" />
        When the button is rendered in the browser the __doPostback() JavaScript method will be added to it's JavaScript onclick event. This will indicate that a postback has occured, that it was the "theButton" that caused the postback, and that it was a "click" event.

        Now in your server side code you will be able to check whether or not it is a page postback...and you can handle the "theButton" click event.

        Comment

        • z1freeride
          New Member
          • Feb 2009
          • 36

          #5
          I get an error: "Control 'ctl00_content_ theButton' of type 'Button' must be placed inside a form tag with runat=server."

          In this particular case I can't use a form with the tag runat=server.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            When you are using an ASP.NET control, such as an ASP.NET button, they must have runat="server".

            For example, the following is an ASP.NET button and requires the runat="server":
            Code:
            <asp:Button ID="theButton" runat="server" />
            The following is an HTML button, it does not require the runat="server"; however, without it this button will not be accessible in your server code:
            Code:
            <input type="button" id="theButton" />
            The same goes for <form> tags. When used in an ASP.NET application, the <form> tag must have a runat="server" so that ASP.NET can access this tag.

            Since you are using Visual Studio, why don't you just add a new Web Form and use that?

            In your solution viewer right click on your project name and select Add -> New Item. Then select "Web Form", give it a meaningful name, and click the "Add" button. This will create an ASPX page for you that you can add items to.

            [edit]
            Actually it looks like you're using a Master Page, so you should probably add a new content page and select your Master Page instead of adding a new Web Form[/edit]

            Comment

            • z1freeride
              New Member
              • Feb 2009
              • 36

              #7
              I already have one form using runat="server" so I'm trying to get a regular html form to post back to the page.

              Comment

              Working...