If the publish button pressed in the zero -question line - the user must get the red warning message:
You cannot publish survey with zero questions
But how to do it? The validate function cannot receive any additional parameters except
object sender, ServerValidateEventArgs e
And we cant even figure out which repeater item sended the command since the publish button not requires any item checkboxses to be checked.Custom validator:
<asp:CustomValidator ID="CustomValidator2" runat="server"
ErrorMessage="You cannot publish survey with zero questions"
ValidationGroup="zeroQuestions" Display="Dynamic" OnServerValidate="IsZeroQuestions">
</asp:CustomValidator>
It raises the server-validation function IsZeroQuestions
how can this function "know" what the questions number of line(Repeater Item) whose raised it?
Well, it means i need to change the way the Publish/Unpublish button working:
From now it will work this way:
protected void PublishThisSurvey(object sender, RepeaterCommandEventArgs e)
{
RepeaterItem ri = Repeater1.Items[e.Item.ItemIndex];
CheckBox chkBox = (CheckBox)ri.FindControl("CheckBox1");
chkBox.Checked = true;
Validate("zeroQuestions");
if (!Page.IsValid)
{
CustomValidator2.ErrorMessage = "Cannot publish this
survey with zero questions";
chkBox.Checked = false;
return;
}
HiddenField hf;
hf = (HiddenField)ri.FindControl("surveyID");
int surveyID = Convert.ToInt32(hf.Value);
HiddenField isPhf = (HiddenField)ri.FindControl("IsPublished_hf");
bool bIsPublished = Convert.ToBoolean(isPhf.Value);
//turn upside
bIsPublished = (bIsPublished) ? false : true;
clsDataAccess myclass = new clsDataAccess();
myclass.UpdateSurveyPublished(surveyID, bIsPublished);
Repeater1.DataBind();
}
and the trigger will be ItemCommand of Repeater:
<asp:Repeater ID="Repeater1" runat="server"
DataSourceID="SurveysSqlDataSource" OnItemCommand="PublishThisSurvey">
No comments:
Post a Comment