简体   繁体   English

ASP中的回发不会刷新控件值

[英]postback in asp doesn't refresh control value

I have a div(runat=server) that contain repeater,this repeater is getting is value from datatable 我有一个包含转发器的div(runat = server),这个转发器从数据表中获取值

when the datatable is empty I do this line of code in asp .net function 当数据表为空时,我在asp .net函数中执行以下代码行

divname.innerHTML="<img src="...>"

on this page there is also a asp:button that fill the datatable with values. 在此页面上,还有一个asp:button,它用值填充数据表。 when pressing the button ,the above line isn't excute,the page offcourse is doing postback, but the div content isn't changing back to his original value(the repeater). 当按下按钮时,上面的行不算行,页面关闭页面正在回发,但是div的内容并没有变回他的原始值(转发器)。

What do I have to do in the postback in order to force the div to get his original values? 为了强制div获取其原始值,我必须在回发中做什么?

This is code example: 这是代码示例:

     sub page_load(..
if ispostback=false then
         run_div()
end if
        end sub

        sub run_div()

    if datatable.Rows.Count=0 then
    divname.innerHTML="<img src="...>"


    end if
    end sub


sub filldata(....

fill datatable
 repeater.datasource=...
    repeater.databind
run_div()

end sub



    html look like this

    <div runat=servver id=divname><asp:repeater>.....
    <asp:button onclick="filldata">

Thanks for any help 谢谢你的帮助

Assuming the variable named datatable is a System.Data.DataTable, remember that it only exists and had data in the context of a sibgle run of the page lifecycle. 假设名为datatable的变量是System.Data.DataTable,请记住该变量仅在页面生命周期的单步运行上下文中存在并且具有数据。 if the page is re-generated (whether it's via a postback or an initial load of the page) the DataTable is empty until it's loaded. 如果页面是重新生成的(无论是通过回发还是页面的初始加载),则DataTable在加载之前为空。

However, the Repeater object is stored in teh ViewState. 但是,Repeater对象存储在ViewState中。 IT will have values on a postback if there were rows on the previous load. 如果先前的加载中有行,则IT将在回发中包含值。

Instead of looking at the number of rows in the table, you should be looking at the Repteater.Items.Count. 与其查看表中的行数,不如查看Repteater.Items.Count。

If repeater.Items.Count = 0 Then
   divname.innerHTML="<img src="...>"    
Else
   ...
End If

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM