[英]How to perform a button click after a postback to open a modal window
我在使按鈕在回發后執行點擊時遇到麻煩。 我正在驗證網頁上的模式窗口內的一些文本框,該文本框僅在單擊按鈕后出現。 當前,在回發之后,網頁將重新打開,並且模式窗口已關閉,需要打開該窗口。 我的代碼中沒有處理程序,單擊該按鈕並運行html代碼以打開模式窗口。 一旦我發回郵件,就需要單擊此按鈕,以便啟動驗證。 我嘗試使用btnSickness.Click(),但它似乎不喜歡這種方法,而且似乎在任何地方都找不到! 碼:
public partial class _Default : System.Web.UI.Page
{
int i = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (i > 0)
{
}
}
protected void chkDoctor_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpDoctor.SelectedValue == "Yes")
{
txtIfNoWhy.ReadOnly = true;
txtIfNoWhy.BackColor = Color.LightGray;
i++;
}
else if (drpDoctor.SelectedValue == "No")
{
txtDocName.ReadOnly = true;
txtHouseName.ReadOnly = true;
txtStreet.ReadOnly = true;
txtTownCity.ReadOnly = true;
txtCounty.ReadOnly = true;
txtPostalcode.ReadOnly = true;
txtInitialDate.ReadOnly = true;
txtTreatmentRecieved.ReadOnly = true;
txtCurrentTreatment.ReadOnly = true;
txtDocName.BackColor = Color.LightGray;
txtHouseName.BackColor = Color.LightGray;
txtStreet.BackColor = Color.LightGray;
txtTownCity.BackColor = Color.LightGray;
txtCounty.BackColor = Color.LightGray;
txtPostalcode.BackColor = Color.LightGray;
txtInitialDate.BackColor = Color.LightGray;
txtTreatmentRecieved.BackColor = Color.LightGray;
txtCurrentTreatment.BackColor = Color.LightGray;
i++;
}
}
}
模態窗口代碼:
<div class"modal" id="myModal"></div>
<div class="row-fluid">
<div class="span2">
<asp:Button runat="server" class="btn" data-toggle="modal" href="#Div1" ID="btnSickness" Text="Submit a Sickness Form" />
<div class="modal hide" id="Div1">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3>Sickness Form</h3>
</div>
<div class="modal-body">
<p>Please fill in the following information regarding your sickness</p>
<br />
<p>Sickness Date From:</p>
<asp:TextBox runat="server" ID="txtSicknessFrom"></asp:TextBox>
<br />
<p>Sickness Date To:</p>
<asp:TextBox runat="server" ID="txtSicknessTo"></asp:TextBox>
<br />
<p>Absence Date To:</p>
<asp:TextBox runat="server" ID="txtAbsenceFrom"></asp:TextBox>
您可以設置一個隱藏字段,告訴模態從服務器返回時顯示。 然后,您可以添加一個pageLoad javascript函數,該函數在每次pageLoad時運行,以檢查是否需要顯示模式。
服務器端 :
hdf_ShowModal.Value = "true";
HTML :
<asp:HiddenField runat="server" ID="hdf_ShowModal" />
Javascript :
function pageLoad(sender, args)
{
if(document.getElementById('<%= hdf_ShowModal.ClientID %>').value == "true")
{
// perform code to show modal
}
}
編輯 :
由於還使用了jquery,因此可以嘗試以下操作來顯示模式:
function pageLoad(sender, args)
{
if($('[id$=hdf_ShowModal]').val() == "true")
$('#myModal').modal({ show: true });
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.