Autopostback not working

R

Ron

Hello all,

I don't understand why my pageis not posting back to the server when I
change the selection on a radio list.

I have a page that both accepts new personal info. or allows editing
to existing info depending on the parameter passed from previous
pages. The radio is supposed to disable the password (and confirm
password) text boxes as well as their validation controls. However,
when you click 'No' (This should perform the above tasks) nothing
happens. However, when you click submit to enter the edited
information: it posts back, performs the OnSelectedIndexChanged
procedure of the radio list as well as the OnClick of the button.
Grrr.

Below is (hopefully) as much code needed to disect the issue while
trying to keep as brief as possible. I thank you in advance.

--Start of code--

<html>
<script runat="server">
sub page_load (source as object, e as eventargs)
FormType.text = "Enter New Employee"

if len(session("empnum")) = 6 then
FormTypeVar = "Edit"
FormType.text = "Edit Personal Information"

else
emppass.enabled = true
empconfirm.enabled = true
end if

If not ispostback and formtypevar = "Edit" then
passchange.enabled = "true"
fill_page() --fills fields with info from DB
end if
end sub

sub Submit_Click (sender as object, e as eventargs)
If page.isvalid then
If FormTypeVar = "New" Then
--perform tasks for adding new employee
Else
--perform tasks for editing info
end if
end if

sub togglepass(sender as object, e as eventargs)
dim temp as boolean = passchange.selecteditem.value
if temp then
passoff = false
emppass.enabled = true
empconfirm.enabled = true
pwvalid.enabled = true
else
passoff = true
emppass.enabled = false
empconfirm.enabled = false
pwvalid.enabled = false
end if
end sub
<body>
<form runat="server">
Password:
<asp:TextBox id="emppass" runat="server" textmode="password"
Columns="25" />
<asp:CustomValidator id="pwvalid" OnServerValidate="password_validate"
errormessage="Your passwords did not match, please try again."
runat="server">*</asp:customValidator>

<asp:TextBox id="empconfirm" runat="server" textmode="password"
Columns="25" />

Change your password?
<asp:RadioButtonList ID="passchange" Enabled="false" RepeatColumns="2"
OnSelectedIndexChanged="togglepass" AutoPostBack="true" runat="server"
<asp:ListItem Value=true Text="Yes" Selected="true"/>
<asp:ListItem Value=false Text="No"/>
</asp:RadioButtonList>

<asp:Button id="submit" onclick="submit_click" text="Submit"
runat="server"/>
</form>
--etc.
 
P

Peter Rilling

Make sure the @AutoPostBack attribute is set on the tag in the HTML. Some
tags such as lists default to false so that the page does not refresh every
time that some event happens.
 
R

Ron Bell

Thanks for your quick replies.

Didn't I do what both of you said with the the following:

<asp:RadioButtonList ID="passchange" Enabled="false" RepeatColumns="2"
OnSelectedIndexChanged="togglepass" AutoPostBack="true" runat="server">

Are either of you telling me to do something different than the above
autopostback="true". Thanks.
 
J

Juan Romero

Do you have any script in the page? I mean, script placed there by you?

If not, just recompile the project.

Ron said:
Maybe this can clarify the problem. I just noticed the little yellow icon
--error on page-- when I click on one of the radio buttons. The error is:

Line:121, Char:3, Error:Object doesn't support this object or method, Code:0

When I view source on the page and goto line 121, this is the code:

<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["form1"];
}
else {
theform = document.form1;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
Line 121--------> theform.submit(); <---------- Line 121
}
// -->
</script>

Thanks again.

Juan Romero said:
Set the radio list Autopostback property to TRUE.
 
H

Harry Simpson

And you're missing the closing </SCRIPT> tag.....

Ron said:
Maybe this can clarify the problem. I just noticed the little yellow icon
--error on page-- when I click on one of the radio buttons. The error is:

Line:121, Char:3, Error:Object doesn't support this object or method,
Code:0

When I view source on the page and goto line 121, this is the code:

<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["form1"];
}
else {
theform = document.form1;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
Line 121--------> theform.submit(); <---------- Line 121
}
// -->
</script>

Thanks again.

Juan Romero said:
Set the radio list Autopostback property to TRUE.
 
H

Harry Simpson

javascript is case sensitive
<asp:Button id="submit" onclick="submit_click" text="Submit"
runat="server"/>
but refers to
sub Submit_Click (sender as object, e as eventargs)

Try being consistent with the case

Harry

Harry Simpson said:
And you're missing the closing </SCRIPT> tag.....

Ron said:
Maybe this can clarify the problem. I just noticed the little yellow
icon
--error on page-- when I click on one of the radio buttons. The error
is:

Line:121, Char:3, Error:Object doesn't support this object or method,
Code:0

When I view source on the page and goto line 121, this is the code:

<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["form1"];
}
else {
theform = document.form1;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
Line 121--------> theform.submit(); <---------- Line 121
}
// -->
</script>

Thanks again.

Juan Romero said:
Set the radio list Autopostback property to TRUE.

Hello all,

I don't understand why my pageis not posting back to the server when I
change the selection on a radio list.

I have a page that both accepts new personal info. or allows editing
to existing info depending on the parameter passed from previous
pages. The radio is supposed to disable the password (and confirm
password) text boxes as well as their validation controls. However,
when you click 'No' (This should perform the above tasks) nothing
happens. However, when you click submit to enter the edited
information: it posts back, performs the OnSelectedIndexChanged
procedure of the radio list as well as the OnClick of the button.
Grrr.

Below is (hopefully) as much code needed to disect the issue while
trying to keep as brief as possible. I thank you in advance.

--Start of code--

<html>
<script runat="server">
sub page_load (source as object, e as eventargs)
FormType.text = "Enter New Employee"

if len(session("empnum")) = 6 then
FormTypeVar = "Edit"
FormType.text = "Edit Personal Information"

else
emppass.enabled = true
empconfirm.enabled = true
end if

If not ispostback and formtypevar = "Edit" then
passchange.enabled = "true"
fill_page() --fills fields with info from DB
end if
end sub

sub Submit_Click (sender as object, e as eventargs)
If page.isvalid then
If FormTypeVar = "New" Then
--perform tasks for adding new employee
Else
--perform tasks for editing info
end if
end if

sub togglepass(sender as object, e as eventargs)
dim temp as boolean = passchange.selecteditem.value
if temp then
passoff = false
emppass.enabled = true
empconfirm.enabled = true
pwvalid.enabled = true
else
passoff = true
emppass.enabled = false
empconfirm.enabled = false
pwvalid.enabled = false
end if
end sub
<body>
<form runat="server">
Password:
<asp:TextBox id="emppass" runat="server" textmode="password"
Columns="25" />
<asp:CustomValidator id="pwvalid" OnServerValidate="password_validate"
errormessage="Your passwords did not match, please try again."
runat="server">*</asp:customValidator>

<asp:TextBox id="empconfirm" runat="server" textmode="password"
Columns="25" />

Change your password?
<asp:RadioButtonList ID="passchange" Enabled="false" RepeatColumns="2"
OnSelectedIndexChanged="togglepass" AutoPostBack="true" runat="server"


<asp:ListItem Value=true Text="Yes" Selected="true"/>
<asp:ListItem Value=false Text="No"/>
</asp:RadioButtonList>

<asp:Button id="submit" onclick="submit_click" text="Submit"
runat="server"/>
</form>
--etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top