master page code:
<asp:UpdatePanel ID="Upi" runat="server">
<ContentTemplate>
<p class="text1" id="lbl_cart" runat="server"></p>
</ContentTemplate>
</asp:UpdatePanel>
client Page code:
<asp:UpdatePanel ID="Upi" runat="server">
<ContentTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/add-button.png" OnClientClick="getcountr(this)"/>
</ContentTemplate>
</asp:UpdatePanel>
如何更新主控制值onclick imagebutton 1 ...
答案 0 :(得分:0)
定义Imagebutton的click事件,如下面的
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
var c= this.Master.FindControl("lbl_cart") as System.Web.UI.HtmlControls.HtmlGenericControl;
c.InnerText = "12122112";
}
这样您就可以修改母版页中的p标签文本。
答案 1 :(得分:0)
在您的客户端页面中尝试以下内容:
<script language="javascript">
function getcountr(obj) {
var t = document.getElementById('<%=Master.FindControl("lbl_cart").ClientID %>');
if (parseFloat(t.innerHTML) > 0) {
t.innerHTML = parseFloat(t.innerHTML) + 1;
}
else {
t.innerHTML = 1;
}
}
</script>
并在母版页中:
<p class="text1" id="lbl_cart" runat="server">0</p>
答案 2 :(得分:0)
您可以找到并更新从母版页继承的子页面中的任何控件:
只需在您的&#39; ImageButton1&#39;旁边编写以下代码即可点击事件:
private void ImageButton1_Click(object sender, EventArgs e)
{
ContentPlaceHolder cp = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
UpdatePanel up1 = cp.FindControl("Upi") as UpdatePanel ;
up1.Visible= true;//Write your logic here.
}