c# - 如何在回发后执行按钮单击以打开模式窗口

标签 c# asp.net html twitter-bootstrap

我无法让我的按钮在回发后执行单击操作。我正在验证网页上模式窗口内的一些文本框,这些文本框仅在单击按钮后出现。目前,回发后,网页重新打开,模态窗口关闭,需要打开模态窗口。我的代码中没有处理程序,单击按钮并运行 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 函数,该函数在每次 pageLoads 时运行,以检查是否需要显示模式。

服务器端:

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 });
}

关于c# - 如何在回发后执行按钮单击以打开模式窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10620050/

相关文章:

html - 右对齐表格中的输入

c# - 在 MVP 模式中我需要多少位演示者

c# - 如何将列表项添加到在代码隐藏中生成的下拉列表?

c# - 禁用asp.net中div内的所有控件

c# - 在类名中添加模型值?

html - div 不会在 IE 10 中对齐,但在 Firefox 中工作正常

html - 歌剧和额外的空间和滚动

c# - 为什么 DELETE 语句在 MySql Workbench 和 PHP/PDO 中运行时会在 MySQL Connector/net 中默默失败?

c# - TransactionScope 内的 Azure Blob 存储上传

c# - 在中等信任主机上使用 quartz.net