详细问题:在gridview加panel,panel初始值为隐藏,点击button后显示,但点击button后没反应,估计是页面刷新了吧,所以又再次隐藏,那要怎样确保操作Panel里面的内容不会导致页面刷新?
部分代码:
<asp:GridView ID="gvMessage" runat="server" AutoGenerateColumns="False" 
                                Width="590px">
                                <Columns>
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <table class="style5" bgcolor="White">
                                                <tr>
                                                    <td colspan="2">
                                                        作者:<asp:Label ID="lblUserName" runat="server" Text='<%# Bind("UserName") %>'></asp:Label>
                                                        于<asp:Label ID="lblCreateDate" runat="server" Text='<%# Bind("CreateDate") %>'></asp:Label>
                                                        留言!</td>
                                                </tr>
                                                <tr>
                                                    <td class="style8" colspan="2">
                                                        <hr size="2" style="background-color: #000000" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        <asp:Label ID="lblMessage" runat="server" Text='<%# Bind("Message1") %>'></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="style11">
                                                        &nbsp;</td>
                                                    <td>
                                                        <table class="style5">
                                                            <tr>
                                                                <td class="style9">
                                                                    <p></a>
                                                                        <asp:Button ID="btnReply" runat="server" BackColor="White" 
                                                                            onclick="btnReply_Click" Text="我要回复" />
                                                                    </p></td>
                                                                <td >
                                                                    <asp:Button ID="btnShow" runat="server" BackColor="White" Text="展开&gt;&gt;" />
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        <asp:Panel ID="Panel1" runat="server" Visible="False">
                                                            <asp:TextBox ID="txtreply" runat="server" BorderColor="#FF6600" 
                                                                TextMode="MultiLine" Width="456px"></asp:TextBox>
                                                            <asp:Button ID="Reply" runat="server" BackColor="#FF6600" BorderColor="White" 
                                                                EnableTheming="True" Text="回复" />
                                                        </asp:Panel>
                                                    </td>
                                                </tr>
                                            </table>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;public partial class AboutUs : System.Web.UI.Page
{
    TeaShopDataContext db = new TeaShopDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        var messages= (from c in db.Message
                        orderby c.MessageId descending
                        select c).Take(7);
        gvMessage.DataSource = messages;
        gvMessage.DataBind();
    }
    protected void btnReply_Click(object sender, EventArgs e)
    {
        Panel Panel1 = (sender as Button).NamingContainer.FindControl("Panel1") as Panel;//获取panel
        Panel1.Visible = true;    }
}
望哪位大神指导一下,万分感激。

解决方案 »

  1.   

    不能在前台js里写吗?什么东西都提交到后台,不刷新才怪 <asp:Button ID="btnReply" runat="server" BackColor="White" 
                                                                                 onclientclick="Show();" Text="我要回复" /><script>
    function Show()
    {
       document.getElementById(“Panel1”).style.display='block';  //显示Panel1
    }
    </script>
      

  2.   

    你刷新整个页面后他又回复到默认值了->默认是隐藏,当然是隐藏了如果你要同时显示隐藏并提并表单,当然还要在客户端写JS咯 <asp:Button ID="btnReply" runat="server" BackColor="White" 
                                                                                 onclientclick="MyShow();" Text="我要回复" />function MyShow()
    {
        $("#Panel1").css("display","block");
    }
      

  3.   

       protected void Page_Load(object sender, EventArgs e)
        {
    if(!ispostback)
    {
            var messages= (from c in db.Message
                            orderby c.MessageId descending
                            select c).Take(7);
            gvMessage.DataSource = messages;
            gvMessage.DataBind();
    }
        }
      

  4.   

    我改了之后为什么会显示SCRIPT5007: 无法获取属性“style”的值: 对象为 null 或未定义 
    AboutUs.aspx, 行179 字符6
      

  5.   

    你使用 jquery获取的吧  在你获取的对象上 加个get(0) 方法试试
      

  6.   

    要刷新获取新数据,用JS实现,会显示SCRIPT5007: 无法获取属性“style”的值: 对象为 null 或未定义 
     AboutUs.aspx, 行179 字符6。
    用if(!ispostback)可以