$('#bn1').click(function () {
$('#textbox1').change();
})
<asp:UpdatePanel runat="server" ID="up123" UpdateMode="Conditional">
<ContentTemplate>
<div style="margin-top: 250px;">
<asp:TextBox runat="server" ID="textbox1" ClientIDMode="Static" AutoPostBack="true" CssClass="DateTimePicker" />
<asp:Button runat="server" ID="bn1" ClientIDMode="Static" Text="clickme" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
在我的内容页面中使用上述功能和母版页时,会导致整页回发而不是部分回发 如果我在没有母版页的情况下使用它,那就完全没问题了吗?
答案 0 :(得分:1)
使return false
停止发生服务器端点击事件,如下所示:
$('#bn1').click(function () {
$('#textbox1').change();
// This stops the server control from doing a click, which
// posts the form back to the server
return false;
});
更新:
要验证哪个控件实际导致回发到服务器,请在Page_Load
事件中执行此操作:
protected void Page_Load(object sender, EventArgs e)
{
var controlIdThatCausedPostBack = String.Empty;
var scriptManager = ScriptManager.GetCurrent(Page);
if (scriptManager != null)
{
var smUniqueId = scriptManager.UniqueID;
var smFieldValue = Request.Form[smUniqueId];
if (!String.IsNullOrEmpty(smFieldValue) && smFieldValue.Contains("|"))
{
controlIdThatCausedPostBack= smFieldValue.Split('|')[1];
}
}
else
{
controlIdThatCausedPostBack = Page.Request.Params["__EVENTTARGET"];
}
if (!String.IsNullOrEmpty(updatePanelControlIdThatCausedPostBack))
{
// Here we have the control ID that causes the post back
}
}