访问用户控件上的母版页控件 [英] Access Master Page Control on User Control

查看:89
本文介绍了访问用户控件上的母版页控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好...


我有两件事.

1.用户控制Gridview.
2.Repeater,位于div内,并出现在跨度的鼠标悬停事件上,在Masterpage上

好吧,每当我单击另一个页面上的按钮并且该页面继承了MasterPage时,用户控件gridview都会更新并显示插入的数据...
并且中继器也应该使用相同的内容进行更新.

就像如果我想同时在Button事件上的User Control Gridview上创建任何DML一样,Repeater应该得到更新.

我尝试获取用户控件上的母版页,从而获得了成功,但是当我尝试获取转发器的对象时,这告诉我对象引用未设置为实例".

这是代码...
在用户控制下

Hello...


I have two things.

1.User Control viz. a Gridview.
2.Repeater, inside a div and appear on mouseover event of an span, on Masterpage

Well whenever I clicked on a Button, which is on another page and this page is inheriting the MasterPage, the user control gridview get updated and show the inserted data...
and the repeater should also be updated with the same...

Like If I want to make any DML on User Control Gridview on Button event simultaneously Repeater should get updated.

I tried to get Master Page on User Controls I got success in this but further when I tried get the object of repeater this tells me "object reference is not set to an instance".

here is the code...
On User Control

con.Open();            
OdbcCommand com = new OdbcCommand("select a.pid,b.productname,b.ThumbImageUrl, a.price,a.total,a.quantity  from tempcart a,product b where a.sessionid=''" + Session["ID"] + "'' and a.pid=b.productid", con);
OdbcDataAdapter da = new OdbcDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
if (ds.Tables[0].Rows.Count > 0) // here checking data in dataset
{
     MasterGrocery mstr = new MasterGrocery();  //Here I''m accessing the MasterPage
     Repeater rptr = (Repeater)mstr.FindControl("gvShow");
     rptr.DataSource = ds;
     rptr.DataBind();
     HtmlControl bbbbb = (HtmlControl)mstr.FindControl("spnMyBag");
     bbbbb.Visible = true;
}



请引导我

关于



Please Guide me

Regards

推荐答案

,您可以像这样在用户控件中访问母版页控件

you can access the master page controls in the user control like that

this.Page.Master.FindControl("txtName")


这篇关于访问用户控件上的母版页控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆