Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button reloads page and IsPostBack acts to be false, WHY?

Status
Not open for further replies.

LizKayl

Programmer
Mar 2, 2004
13
US
I have my vb script declared, then inside the script tags, I have my
Code:
sub Page_Load
      if notIsPostBack
             ...do some stuff to set up the page...
      end if
end sub

sub buttonAction(s as object, e as EventArgs)
     ...perform a query...
     ...call a function to set option box to invisible...
     ...call a function to set labels to visible...
</script>

...head and start of page...
<form runat="server">
<td colspan="1">
    <b>Room :</b>&nbsp;
    <ASP:DropDownList id="roombox"
                      runat="server">
    </asp:Dropdownlist>
    <asp:RequiredFieldValidator 
         ControlToValidate = "roombox" 
         ErrorMessage = "*" 
         InitialValue = "Select" 
         Display="dynamic" 
         runat = "server"/> 
    <ASP:label id="roomlabel"
               runat="server"
               visible = "false"/>
</td>
<td><center><form> <asp:button id="submit" 
	  Button="button"
	  style="width:120;"
	  name="Submit" 
	  text="Reserve Room" 
          value = "true" 
	  onClick="btnAction"
	  autopostback="true"
	  runat="server"/></form>
</center>
</td>
</form>

 
The only thing I see wrong with this code is the open and closing form tags around the button itself.

If you get rid of those does it still never act like it is posting back?
 
I added them in because, well, it's not up there, but inside the form runat="server" tag, I have a calendar that postbacks and changes the page when a day is selected. If I have form - non-runat tags inside the main form around the calendar it works. It postbacks and updates when the user selects. Without them, calendar selects do Nothing.

Similarly with the Button action. without those tags, the button activates the validations, but never calls the ButtonAction function on click. I need it to do both. Thank you for your help. I'm baffled.
 
onClick="btnAction"
sub buttonAction
Why are the names different?
 
This might seem like a silly question but you say the validation is called. That means something is not passing validation.

What happens if all required parameters of validation are passed and you don't have those form tags?
 
Visual studio.net complains if I put 2 forms on a page.
<form runat="server">
and a nested form
<form>

I guess your viewstate is in <form runat="server"> but if you click the button with ID submit the <form> is submitted.

Try this.
Code:
<form runat="server">
  <asp:label id=lblViewstate text='<%#"viewstate value is: " & request("__VIEWSTATE") %>' />
  <asp:button id="goodButton" text="good button" />
  <form>
      <asp:button id="badButton" text="bad button" />
  </form>
</form>



Greetings, Harm Meijer
 
evaleah (Programmer) Apr 21, 2004
This might seem like a silly question but you say the validation is called. That means something is not passing validation.

What happens if all required parameters of validation are passed and you don't have those form tags?


If I don't have the form tags, the page has the validations work, but nothing else happens. If I turn off the validation for the button, it still changes nothing.
 
Harm Meijer, thank you for your advice and welcome, but I tried your code in my program and nothing appears.
 
I'm confused by a few things,
The calander has a onClick OnSelectionChanged method that will postback the buttons should all have a onClick method, why the autopost back and so many form tags like asked above.
Marty
 
Thank you for all your help. I put the form tags in because otherwise it wouldn't run at all. Then I realized my mistake. I set the calendar to 'autopostback = "true" and got rid of the little form tags ( the ones that don't say runat=server) and it runs properly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top