我的问题是每当我点击按钮时,在点击事件上调用按钮后重新加载空页面。 该页面仅包含以下代码
<html>
<head></head>
<body>2015</body>
</html>
我想要做的是显示表单已提交的消息或重定向到其他页面。 Response.Direct
和Server.Transfer
无法正常工作,我厌倦了将表单包装在一个面板中并创建一个不同的面板,在提交表单后设置为可见,如this示例但是没有每次我点击页面重新加载的按钮时都会解决问题,如上面的代码所示。我不能使用OnClientclick="return false;"
,因为我希望调用我的onClick事件。这是我的一些表单代码(按钮的ID是btnSumbitSurvey
):
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div id="wrapper">
<div id="page-wrapper">
<div class="wrapper-content" runat="server" >
<div runat="server" id="SelectLang">
<asp:Label ID="lblLanguage" runat="server" CssClass="select-lang" style="text-align: center;" Text="Select Survey Language | اختر لغة الاستبيان"></asp:Label>
<asp:RadioButtonList ID="rblLanguage" OnSelectedIndexChanged="ddlSelectedIndexChanged" runat="server" AutoPostBack="True" >
</asp:RadioButtonList>
</div>
<div ID="details" class="survey-details" runat="server" Visible="False">
<span runat="server" class="name" ID="SurveyName"></span>
<p runat="server" class="desc" ID="SurveyDescription"></p>
<div runat="server" id="questionsList" >
<asp:Repeater ID="rptQuestionsEng" runat="server" Visible="False" OnItemDataBound="rpt_ItemDataBound" >
<ItemTemplate>
<div class="question">
<asp:HiddenField ID="hide" Value='<%# Bind("QuestionId") %>' runat="server" />
<asp:Label runat="server" ID="lblQuestion" Text='<%# Bind("QuestionEng") %>' CssClass="questionLabel"></asp:Label>
<asp:RequiredFieldValidator ID="rfvEng" runat="server" ErrorMessage="*" Display="Dynamic" ControlToValidate="rblQuestionEng" ForeColor="red" ></asp:RequiredFieldValidator>
<asp:RadioButtonList runat="server" ID="rblQuestionEng">
</asp:RadioButtonList>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
<asp:Button ID="btnSumbitSurvey" runat="server" Text="Submit" OnClick="btnSubmitSurvey_Click" Visible="False" class="btn"/>
</div>
</div>
</div>
</div>
</form>
代码背后:
protected void btnSubmitSurvey_Click(object sender, EventArgs e)
{
if (rblLanguage.SelectedValue.Equals("1"))
{
List<Response> responsesList = new List<Response>();
foreach (RepeaterItem item in rptQuestionsEng.Items)
{
Response response = new Response();
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
var rbl = (RadioButtonList)item.FindControl("rblQuestionEng");
if (!string.IsNullOrEmpty(rbl.SelectedValue))
{
answerId = Convert.ToInt32(rbl.SelectedValue);
response.QuestionResponse = rbl.SelectedItem.Text;
response.ResponseDate = DateTime.Now;
response.SurveyId = _surveyId;
response.PateintSurveyId = _patientSurveyId;
}
}
var hide = item.FindControl("hide") as HiddenField;
var id = hide.Value;
int questionId = Convert.ToInt32(id);
response.QuestionAnswerId = _blSurvey.GetQuestionAnswer(questionId, answerId);
responsesList.Add(response);
}
if (_blResponse.AddResponse(responsesList))
{
Response.Redirect(Enums.ReferenceLinks.PostSubmission + "?E=F", true);
//postPanel.Visible = true;
//prePanel.Visible = false;
//SubmitMsg.InnerHtml = "Thank you for participating, your submission has been received";
}
}
}
答案 0 :(得分:0)
确保您已检查过IsPostBack -
if (!IsPostBack)
{
// load defaults, language list, repeater etc.
}
我猜您没有使用它,因此每次发布表单时都会加载默认设置并且条件不符合。
答案 1 :(得分:0)
我花了好几个小时试图找出问题所在。最后,我删除了我页面中的所有javascript代码,特别是我在页脚中的代码,并且它有效。