我的問題是,每當我點擊一個按鈕時,在點擊事件後調用按鈕後,空白頁面會重新加載。 該頁面包含以下代碼只按鈕點擊重新加載空白頁面
<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";
}
}
}
你沒有說哪個按鈕導致重定向,並沒有顯示代碼隱藏,這是最重要的部分 –
@FabioLuz好吧對不起,我會更新問題 – RubaRamm
是你的條件rblLanguage.SelectedValue。等於(「1」)是否爲真?和_blResponse.AddResponse(responsesList)返回true? –