1
嗨我有一個按鈕,我正在開發的網站上工作正常,然後我添加了一些樣式和引導到網頁昨天,今天它不工作。邏輯看起來很好,所以我不確定會出現什麼問題。按鈕突然停止工作
我在我的Page_Load事件處理程序指向有效的功能,但由於某些原因,當我點擊按鈕的功能是不是叫:
protected void Page_Load(object sender, EventArgs e)
{
SendButton.Click += new EventHandler(SendButton_Click);
//Some other code I have left out for simplicity
}
public void SendButton_Click(Object sender, EventArgs e)
{
UserCredential sendingUser = (UserCredential)Session["authenticatedUser"];
UserCredential receivingUser = Global.Users.Find(m => m.UserID == Convert.ToInt32(Session["receivinguserid"]));
Global.Users.Find(m => m.UserID == (int)sendingUser.UserID).Conversations.Find(t => t.ReceivingUserID == receivingUser.UserID).ReadMessageList.Add(new Message(MessageTextBox.Text, (int)sendingUser.UserID, DateTime.Now));
Global.Users.Find(m => m.UserID == (int)receivingUser.UserID).Conversations.Find(t => t.ReceivingUserID == sendingUser.UserID).UnReadMessageList.Add(new Message(MessageTextBox.Text, (int)sendingUser.UserID, DateTime.Now));
ChatLabel.Text += "<br>" + sendingUser.Name.ToString() + ": " + MessageTextBox.Text + " " + DateTime.Now.ToString("ddd, dd MMMM HH:mm");
MessageTextBox.Text = String.Empty;
}
這裏是我的html頁面中,SendButton一直在底部:
<form id="form1" runat="server">
<div class="row">
<div class="well center" style="width:50%">
<a>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server">
</asp:Timer>
</a>
<asp:UpdatePanel runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="tim" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Timer ID="tim" Interval="5000" Enabled="true" OnTick="UpdateChat" runat="server"></asp:Timer>
<asp:Label ID="ChatLabel" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:TextBox ID="MessageTextBox" runat="server" Width="438px"></asp:TextBox>
<asp:Button ID="SendButton" runat="server" Text="Send" OnClientClick="return false"/>
</div>
</div>
</form>
在IE上使用F12,看看你的DOM是否和以前一樣,你沒有改變一些ID或類? – pix
你爲什麼要連接Page_Load中的事件處理程序?爲什麼不在聲明的按鈕上設置它?你爲什麼要返回錯誤的「OnClientClick」?似乎會阻止回發。 – mason