在点击之前的引导模式更改标签文本 [英] Change label text on bootstrap modal before click

查看:103
本文介绍了在点击之前的引导模式更改标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这一个标签控件的自举模式。它是通过点击一个按钮启动,我想改变标签的文本它启动之前。在出现的文本来自于它的C#结束......但从未触发。我想回发不会发生(我猜显示模式阻止它?),使文本未设置。

我想实现的是:点击按钮,设置标签文本(文本必须来自后端),显示模式。以下是我迄今为止:

 < ASP:按钮的ID =btnEasy=服务器的CssClass =BTN BTN-成功文本=易WIDTH =200像素HEIGHT =50像素数据切换=莫代尔数据目标=#modalQuestion数据的背景=静态数据的键盘=假的OnClick =btnEasy_Click/>< D​​IV CLASS =模式变脸ID =modalQuestion的tabindex = -  1角色=对话框中的咏叹调-labelledby =questionHeader>
  < D​​IV CLASS =模式,对话框的角色=文件>
    < D​​IV CLASS =模式内容>
      < D​​IV CLASS =模头>
        < H4类=模式标题ID =questionHeader>简单的问题< / H4>
      < / DIV>
      < D​​IV CLASS =模体>
        < ASP:的UpdatePanel ID =UpdatePanel1=服务器的UpdateMode =条件>
              <&的ContentTemplate GT;
                < ASP:标签ID =lblQuestion=服务器文本=问题>< / ASP:标签>
                  < BR />
                  < BR />
                < ASP:标签ID =lblAnswer=服务器文本=答案>< / ASP:标签>
              < /&的ContentTemplate GT;
              <&触发器GT;
                  < ASP:AsyncPostBackTrigger控件ID =btnEasy事件名称=点击/>
                  < ASP:AsyncPostBackTrigger控件ID =btnShowAnswer事件名称=点击/>
              < /触发器>
          < / ASP:的UpdatePanel>
      < / DIV>
      < D​​IV CLASS =模式躯>
        < ASP:按钮的ID =btnShowAnswer=服务器的CssClass =BTN BTN-主要文本=显示答案UseSubmitBehavior =假的OnClick =btnShowAnswer_Click/>
        < ASP:按钮=服务器的CssClass =BTN BTN-默认的数据驳回=模式文本=关闭/>
      < / DIV>
    < / DIV>
  < / DIV>
< / DIV>

C#:

 保护无效btnEasy_Click(对象发件人,EventArgs的发送)
{
    lblQuestion.Text =易点击
}


解决方案

在btnEasy_Click功能,设置文本值后,发出的JavaScript code将被执行。
例如:

 保护无效btnEasy_Click(对象发件人,EventArgs的发送)
{
    lblQuestion.Text =易点击
    如果(!ClientScript.IsStartupScriptRegistered(JSScript))
    {
        ClientScript.RegisterStartupScript(this.GetType(),JSScript,
        ShowModalPopUp());
    }
}

写您的js函数:

 <脚本>
    功能ShowModalPopUp(){
       $('#modalQuestion')模态('秀')。
    }
< / SCRIPT>

I have a bootstrap modal with a label control in it. It is launched by clicking a button and I want to change the text of the label before it launches. The text that appears will come from the C# end of it... but that never triggers. I guess the postback never occurs (I am guessing showing the modal is blocking it?) so the text isn't set.

What I am trying to achieve is: Click button, set label text (the text has to come from the back end), show modal. Here is what I have so far:

<asp:Button ID="btnEasy" runat="server" CssClass="btn btn-success" Text="Easy" Width="200px" Height="50px" data-toggle="modal" data-target="#modalQuestion" data-backdrop="static" data-keyboard="false" OnClick="btnEasy_Click"/>

<div class="modal fade" id="modalQuestion" tabindex="-1" role="dialog" aria-labelledby="questionHeader">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title" id="questionHeader">Easy Question</h4>
      </div>
      <div class="modal-body">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
              <ContentTemplate>
                <asp:Label ID="lblQuestion" runat="server" Text="Question"></asp:Label>
                  <br />
                  <br />
                <asp:Label ID="lblAnswer" runat="server" Text="Answer"></asp:Label>
              </ContentTemplate>
              <Triggers>
                  <asp:AsyncPostBackTrigger ControlID="btnEasy" EventName="Click" />
                  <asp:AsyncPostBackTrigger ControlID="btnShowAnswer" EventName="Click" />
              </Triggers>
          </asp:UpdatePanel>
      </div>
      <div class="modal-footer">
        <asp:Button ID="btnShowAnswer" runat="server" CssClass="btn btn-primary" Text="Show Answer" UseSubmitBehavior="false" OnClick="btnShowAnswer_Click"/>
        <asp:Button runat="server" CssClass="btn btn-default" data-dismiss="modal" Text="Close" />
      </div>
    </div>
  </div>
</div>

C#:

protected void btnEasy_Click(object sender, EventArgs e)
{
    lblQuestion.Text = "Easy clicked";
}

解决方案

In the btnEasy_Click function, after setting the text value, emit the javascript code which will be executed. eg.

protected void btnEasy_Click(object sender, EventArgs e) 
{   
    lblQuestion.Text = "Easy clicked";
    if(!ClientScript.IsStartupScriptRegistered("JSScript"))
    {
        ClientScript.RegisterStartupScript(this.GetType(),"JSScript",
        "ShowModalPopUp()");
    } 
}

Write your js function:

<script>
    function ShowModalPopUp(){
       $('#modalQuestion').modal('show');
    } 
</script>

这篇关于在点击之前的引导模式更改标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆