![](/img/trans.png)
[英]ASP.NET how to post updates during postback (I know how the postback works but still…)
[英]I want to Disable postback of asp.net Button but will still be do the same job by jQuery?
我正在嘗試制作一個聊天應用程序。這是我的aspx.cs頁面的源代碼
public partial class home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private string chatitems
{
get
{
if(Application["un"]==null)
Application["un"] = "";
return Application["un"].ToString();
}
set
{
Application["un"] = value;
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = chatitems;
}
protected void Button1_Click(object sender, EventArgs e)
{
chatitems = txt.Text + "<br />" + chatitems;
}
}
我希望按鈕執行相同的操作,但沒有任何回發。 可以通過使用jQuery來實現嗎? 如果是,那么誰能告訴我如何?
而不是使用<asp:Button ID="Button1" ... />
服務器端控件,而只需使用類型為commit的輸入html元素
<input id="submitButton" type="submit" value="Submit"/>
然后將事件處理程序附加到您的on click事件的按鈕上。 這通常是在頁面底部的結束標記之前的腳本中完成的
</body>
如下所示:
<script type="text/javascript">
// select the button element
var button = document.getElementById('submitButton');
// add an event listener for the on click event.
button.AddEventListener("onClick", function(){
var txt = document.getElementById('<%=txt.ClientId%>');
// I suppose that you will define the chatitems somewhere above, because I don't //get its use, reading your code.
chatitems += txt.val()+"<br/>";
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.