2020年12月31日星期四

How to make bootstrap alert popup in another page when clicking on a button

Im trying to make an admin page where if i click on the button 'send', the message will be sent and there will popup a bootstrap alert on the employee page. I have already the bootstrap alert setup, the message for the first time is shown. After I close and i send a message again i dont see any alert. I think it needs to be triggered when i click on the send button but im struggling about how to do that. Hope anyone can show me a simple way. Here is the code for the admin page to send:

<form action="" method="post">      <fieldset>          <tr>              <div class="form-group">                  <td>Send message</td>                  <input type="text" id="msg" name="Bericht"/>              </div>                <div class="form group">                  <button type="submit" id="sendButton"  asp-page-handler="Submit" >Send</button>              </div>            </tr>         </fieldset>    </form>    

And here is the code for the employeepage where there should be a popup bootstrap alert from the admin page

<script src="~/lib/signalr.js"></script>    <script type="text/javascript">  // Start the connection.  var connection = new signalR.HubConnectionBuilder()      .withUrl('/speedalarmhub')      .build();          connection.on('ReceiveMessage', function (message) {                                    var encodedMsg = message;                                    // Add the message to the page.                                    document.getElementById("output").innerHTML = encodedMsg;                                            });      // Transport fallback functionality is now built into start.      connection.start()          .then(function () {                console.log('connection started');              connection.invoke('SendMessage');          })          .catch(error => {              console.error(error.message);          });  </script>    <div class=container>      <div class="alert alert-warning">          <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>          <p id="output"></p>      </div>  </div>  

And here is the code for the Submit handler

public void  OnPostSubmit(NotificationModel notif)          {              DateTime datenow = DateTime.Now;              CreateNotification(datenow, notif.Bericht);                    }              public void CreateNotification(DateTime convdayid, string Bericht)           {                              var cs = Database.Database.Connector();                using var con = new NpgsqlConnection(cs);              con.Open();                var sql = "INSERT INTO notification(bericht, datumnu) VALUES(@Msg, @Date)";              using var cmd = new NpgsqlCommand(sql, con);              cmd.Parameters.AddWithValue("Msg", Bericht);              cmd.Parameters.AddWithValue("Date", convdayid);                                            cmd.Prepare();                cmd.ExecuteNonQuery();              con.Close();            }  
https://stackoverflow.com/questions/65507842/how-to-make-bootstrap-alert-popup-in-another-page-when-clicking-on-a-button December 30, 2020 at 09:35PM

没有评论:

发表评论