您好我在开发的网站上有一个按钮正常工作,然后我昨天在网页上添加了一些样式和引导程序,今天它无法正常工作。所有逻辑看起来都很好,所以我不确定会出现什么问题。
我的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>
答案 0 :(得分:2)
删除或清除按钮的OnClientClick="return false"
。
如果(客户端)javascript按钮处理程序返回false
,那么整个表单都不会被提交,因此永远不会到达您的服务器端代码。