...

View Full Version : PostBack clearing errors!!! help



jay4
07-05-2012, 08:00 PM
when i select the acknowledgement checkbox that has autopostback, all errors on my page is cleared and will allow form submission. it is set to autopostback to enable the submit image button in some cases that i've tested the page has been submitted with errors visible. please help code below.

-----code on page -----
<telerik:RadButton ForeColor="white" ID="RegisterCheckBox" OnClick="RegisterCheckBox_CheckedChanged" runat="server" ToggleType="CheckBox" ButtonType="ToggleButton"
AutoPostBack="true" CausesValidation="true" EnableEventValidation="false" >
<ToggleStates>
<telerik:RadButtonToggleState Text="Acknowledgement" />
<telerik:RadButtonToggleState Text="Acknowledgement" />
</ToggleStates>
</telerik:RadButton>

<asp:ImageButton ImageUrl="images\create_button_grey.png" Visible="false" ID="CreateUserButtonDisable" runat="server"
onclck="CreateUserButton_Click" />
<asp:ImageButton ImageUrl="images\create_button.png" Visible="true" ID="CreateUserButton" runat="server"
onclick="CreateUserButton_Click" />


-----code behind page-----

protected void RegisterCheckBox_CheckedChanged(object sender, EventArgs e)
{
CreateUserButton.Visible = RegisterCheckBox.Checked;
CreateUserButtonDisable.Visible = !RegisterCheckBox.Checked;
CreateUserButton.Enabled = CreateUserButton.Visible;
CreateUserButtonDisable.Enabled = false;
}

alykins
07-05-2012, 08:07 PM
not really clear what the issue is (or at least I am not understanding it)... but you may find luck changing the code behind to this...


protected void RegisterCheckBox_CheckedChanged(object sender, EventArgs e)
{
if(!IsPostBack)
{
CreateUserButton.Visible = RegisterCheckBox.Checked;
CreateUserButtonDisable.Visible = !RegisterCheckBox.Checked;
CreateUserButton.Enabled = CreateUserButton.Visible;
CreateUserButtonDisable.Enabled = false;
}
}

jay4
07-05-2012, 09:21 PM
Hey alykins thanks for the reply I've tried it with the !PostBack but the validation in place is still being bypassed after the page is being post back when the checkbox is selected. ive tried it with the causesvalidation property set to both true and false with no success.

alykins
07-06-2012, 12:04 PM
ok- then without any code... make a list of requirements/steps (bc I am not clear on what you are trying to do)... I assume it has a form so it should look like
1) User enters information on a form
2) User clicks submit
3) Page needs to validate information
4) If it is invalid it needs to blah blah blah

and so on... I need to know that.

jay4
07-06-2012, 07:47 PM
ok no problem.

1) User enters information on a form
2) User clicks checkbox to acknowledge they have read terms of service and enable submit image button.
3)page should post back after checkbox is clicked so that the submit image button can enable.
4) Page needs to validate information. (there is also dynamic validation thrown when there are errors in the field in focus)
5)if page is invalid throw error message to tell user what is wrong on the page and not allow form to be submitted to database until all errors are corrected.
6) if valid allow form to be submitted.


as of right now the errors are being thrown on the page but after the checkbox is clicked and the page is postback all errors have disappeared and will allow submission with the incorrect input into the database.

alykins
07-06-2012, 08:54 PM
ok- I understand now the problem.
How are you validating? is it something like below?


private void Page_Load(...){...}

private Bool pageValid(){
//something to validate... other function calls etc.
}

protected void btnSubmit_OnClick(object sender, EventArgs e){
if(pageValid())
{
//code to do your submitting, call database, whatever
}
else
{
//throw all your error messages
}


if your validation on the backend is like that- then your client side validation might be broken or validating something you are missing. Try your test scenarios with javascripting turned off... do you get past the errors and submit bad code? Client side validation should be an exact copy of serverside- it just makes it faster bc they don't have to wait for postback.

Edit: If that still doesn't answer your Q- can you post your code behind without DB conn strings and what not... you can PM me if you'd like. I do not know how much I will be on over the weekend- I might not be able to respond till Monday

jay4
07-06-2012, 09:13 PM
i do not have a

private Bool pageValid()
{
//something to validate... other function calls etc.
}

i can send you the code just incase. so I will pm you thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum