473,383 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Post Back without runat="server" ?

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

Expand|Select|Wrap|Line Numbers
  1. <form action="test.aspx" method="post">
  2.     <input type="text" id="blah" />
  3.     <input type="submit" value="post" />
  4. </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.
Mar 19 '09 #1
6 6136
Frinavale
9,735 Expert Mod 8TB
Are you using Visual Studio to create your application?
Mar 20 '09 #2
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.
Mar 20 '09 #3
Frinavale
9,735 Expert Mod 8TB
In that case you should use the __doPostback('controlID','') 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:
Expand|Select|Wrap|Line Numbers
  1. <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.
Mar 20 '09 #4
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.
Mar 21 '09 #5
Frinavale
9,735 Expert Mod 8TB
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":
Expand|Select|Wrap|Line Numbers
  1. <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:
Expand|Select|Wrap|Line Numbers
  1. <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]
Mar 23 '09 #6
I already have one form using runat="server" so I'm trying to get a regular html form to post back to the page.
Mar 23 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Matt | last post by:
I want to know what is the purpose of runat="server" attribute?? For example, for a submit button, it just submit the form data to the server, whats the differences between <input...
1
by: Matt | last post by:
If the web control has runat="server" attribute, can we say that control is built on the server (on the fly), and not static control?? Please advise.
6
by: Martin Eyles | last post by:
Hi, I have a page that contains the following <div runat="server" id="Pikea"> <object runat="server" id="PiTV" style="width:560px; height:560px"...
4
by: COHENMARVIN | last post by:
I'm a asp programmer starting out with asp.net. I understand that an asp form can post to its own page and that this allows validation of form fields on the server. But suppose all the controls...
3
by: Jim in Arizona | last post by:
Most of the asp.net learning I've done has been from books that were written during the 1.0 framework. I didn't have a copy of visual studio when I started reading them then I got a hold of VS 2005...
11
by: gunjan.mait | last post by:
hi, i wanted to know the exact use of runat="server" which is being used is ASP.NET why we every time need to use it, even when i want to do the work at client side? How to do simple processings...
2
by: Bob | last post by:
Hi, in aspx file, i defined this: <input id="Button2" type="button" value="button" runat="server" onclick="klik()"/> This 'onclick' event is a clientclick (starting the Javascript function...
4
by: Chris | last post by:
Hi, i 'm experimenting with postback and i tried that with a button server control and an Html input button but with runat="server". The button server control causes a postback, but not the...
19
by: Scott M. | last post by:
Why do we need runat="server" on our <headtags?
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.