Page.ClientScript.RegisterStartupScript not showing messages for 2nd time

后端 未结 3 1978
清酒与你
清酒与你 2021-02-14 01:38

I\'m using Page.ClientScript.RegisterStartupScript for displaying alert messages. it works fine for the first message, however second message wont display. Though i

相关标签:
3条回答
  • 2021-02-14 02:02

    solution with more than one popup modal type

    ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString("N"), "openModal('" + id + "','" + Title + "','" + Message + "');", true);
    

    Below script shall be kept in master page

    <script type="text/javascript">
        function openModal(id, title, message) {
            $('#' + id + ' .modal-header h4').html(title);
            $('#' + id + ' .modal-body').html(message);
            $('#' + id).modal('show');
        }
    </script>
    

    Here parameter id holds the respective bootstrap modal(default, info, danger, warning, success)

    place the below in master page form tag, then repeat the same by replacing the class name "modal-primary" with "modal-info","modal-warning", "modal-dialog","modal-success","modal-danger".

    <div class="example-modal">
      <div class="modal modal-primary" id="primaryModal">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">Modal Primary</h4>
            </div>
            <div class="modal-body">
            <p>One fine body&hellip;</p>
            </div>
            <div class="modal-footer">
            <button type="button" class="btn btn-outline pull-left" data-dismiss="modal">Close</button>
            </div>
          </div>
    <!-- /.modal-content -->
        </div>
    <!-- /.modal-dialog -->
      </div>
    <!-- /.modal -->
    </div>
    <!-- /.example-modal -->
    

    In your master page add reference to bootstrap.min.js and bootstrap.min.css

    This will enable the bootstrap model popup.

    reference: source

    0 讨论(0)
  • 2021-02-14 02:17

    Use different type or key to register second script as:

    A client script is uniquely identified by its key and its type. Scripts with the same key and type are considered duplicates. Only one script with a given type and key pair can be registered with the page. Attempting to register a script that is already registered does not create a duplicate of the script.

    (taken from MSDN)

    or just concatenate both script string.

    Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('FiveDot File uploaded successfully'); alert('TwoDot File uploaded successfully');", true);
    
    0 讨论(0)
  • 2021-02-14 02:25

    Use different keys

    Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('FiveDot File uploaded successfully');", true);
    Page.ClientScript.RegisterStartupScript(GetType(), "msgbox1", "alert('TwoDot File uploaded successfully');", true);
    
    0 讨论(0)
提交回复
热议问题