当前位置: 代码迷 >> ASP.NET >> 怎么把放在 Ajax UpdatePanel 里面的控件给我揪出来
  详细解决方案

怎么把放在 Ajax UpdatePanel 里面的控件给我揪出来

热度:1361   发布时间:2013-02-25 00:00:00.0
如何把放在 Ajax UpdatePanel 里面的控件给我揪出来!
把一个   Label1   放到   UpdatePanel   里面,

label   =   (Label)ctrl.FindControl( "Label1 ");

调试提示:label   为   null,运行出错:未将对象引用设置到对象的实例

但是只要把   Label1   拖到   UpdatePanel   外面,是没问题的!

大家帮帮忙吧。

------解决方案--------------------------------------------------------
<script runat= "server " language= "vb ">
Sub ttk(sender as object,e as system.eventargs)
Dim lb1 as label
lb=page.findcontrol( "label1 ")
lb.text= "你好,这是updatepanel里的label "
Eend sub
</script>

<form runat= "server ">
<asp:Updatepanel id= "update1 " ChildrenAsTriggers= "true " runat= "server " UpdateMode= "Always ">
<contenttemplate>
<asp:label runat= "server " ID= "label1 "/>
<cc1:popupwin id= "ppw " style= "Z-INDEX: 105; right: 0px; POSITION: absolute; TOP: 128px " runat= "server " width= "230px " height= "150px " windowsize= "300, 200 " windowscroll= "False " dockmode= "BottomLeft " colorstyle= "Blue " gradientdark= "210, 200, 220 " textcolor= "0, 0, 3 " shadow= "125, 90, 160 " lightshadow= "185, 170, 200 " darkshadow= "128, 0, 102 " visible= "False " showlink= "True " OffsetX= "0 ">
</cc1:popupwin>
<asp:Timer id= "tm1 " runat= "server " enabled= "true " interval= "10000 " ontick= "ttk "> </asp:Timer>
</contenttemplate>
</asp:Updatepanel>
</form>
------解决方案--------------------------------------------------------
他会每隔10秒更新label1的内容,你也可以把它改成
Sub ttk(sender as object,e as system.eventargs)
Dim lb1 as label
lb=page.findcontrol( "label1 ")
lb.text= "你好,这是updatepanel里的label "
Eend sub

to

Sub ttk(sender as object,e as system.eventargs)
Dim lb1 as label
lb=page.findcontrol( "label1 ")
lb.text=now()
Eend sub

------解决方案--------------------------------------------------------
Updatepanel 是要放一个
在body中 <asp:ScriptManager ID= "ScriptManager1 " runat= "server "> </asp:ScriptManager>

控件才能使用

------解决方案--------------------------------------------------------
UpdatePanel控件熟悉?我也不是很熟悉!菜鸟 !
下面的你参考!参考
<asp:UpdatePanel ID= "UpdatePanel1 " runat= "server " UpdateMode= "Conditional ">
<ContentTemplate>
<asp:Button ID= "Button1 " runat= "server " OnClick= "Button1_Click " Text= "确定 " />
<asp:Button ID= "Button2 " runat= "server " Text= "取消 " OnClick= "Button2_Click " />

<asp:Label runat= "server " ID= "InputTimeLabel "> <%=DateTime.Now %> </asp:Label>
</ContentTemplate>
</asp:UpdatePanel>

------解决方案--------------------------------------------------------
linjone()说得对
刚才忘记放 <asp:ScriptManager ID= "ScriptManager1 " runat= "server "> </asp:ScriptManager>

------解决方案--------------------------------------------------------
Up
------解决方案--------------------------------------------------------
  相关解决方案