当前位置:编程学习 > C#/ASP.NET >>

.net的master page下的内容页内如何引用服务端控件实现回调 高手请进!在线等

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 
  <script language="javascript" type="text/javascript" >  
  function OpenModalDialog(url, name) 

    var vReturnValue; 
    if(url != null) 
    { 
        vReturnValue = window.showModalDialog(url, "#1", "dialogHeight: 400px; dialogWidth: 600px; dialogTop: 100px; dialogLeft: 100px; edge: Raised; center: Yes; help: No; resizable: No; status: No;"); 
    } 
    else 
    { 
        alert("No URL passed to open"); 
    } 
    if(vReturnValue != null && vReturnValue == true) 
    { 
        __doPostBack(' <%=Image3.UniqueID%>', ""); 
      
    } 
    else 
    {  
        return false; 
    } 

  </script> 
... 
<asp:LinkButton ID="Image3" runat="server" OnClick="Image3_Click"> </asp:LinkButton> 
</asp:Content> 


注用__doPostBack(' <%=Image3.ClietID%>', ""); 并不能实现回调
    __doPostBack(' <%=Image3.UniqueID%>', "");能实现回调,
可执行回调后(比如DATAGRID的重新绑定),DATAGRID却不刷新....
     protected void Image3_Click(object sender, EventArgs e) 
    {    
        grdWorkProc.DataSource = workproc.GetJuniorWorkProList(Session["SelectedNode"] as string); 
        grdWorkProc.DataBind(); 
    } 

为什么执行了DATAGRID却不刷新,.net的master page下的内容页内如何引用服务端控件实现回调 ?在线等......急!
--------------------编程问答-------------------- 既然都已经Image3_Click事件了,那就不是回调的问题了。在workproc.GetJuniorWorkProList上找原因。 --------------------编程问答-------------------- 晕,楼上的,这个问题就不要怀疑了,这个肯定是没问题的
因为如果我点击image3的话,同样触发该事件是可以刷新数据的 --------------------编程问答-------------------- 你怎么知道能够回调? --------------------编程问答-------------------- 设断点..已经执行了呀..晕..
至少2003的时候这样是肯定能刷新数据的,项目中经常用
可是05不知道为什么就不行了:(,难道不支持了?还是需要什么配置!
请高手指教..这个问题已经困扰一段时间了,可没人能回答..这是真实存在的问题呀
其实最终的问题是语句执行了,可是DATAGRID却不刷新,而如果你直接点击的话,却是可以刷新的
所以应该是回调时还要注意什么问题,请高手指教,真是没办法,着急 --------------------编程问答--------------------
引用楼主 jzhjzhjzh 的帖子:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 
  <script language="javascript" type="text/javascript" >  
  function OpenModalDialog(url, name) 

    var vReturnValue; 
    if(url != null) 
    { 
        vReturnValue = window.showModalDialog(url, "#1", "dialogHeight: 400px; dialogWidth: 600px; dialogTop: 100px; dialogLeft: 100px; edge: Raised; ce…

你先把母版页里有哪些东东,还有子页面有什么东东,说清楚,分析分析.
事件是发生在哪的? --------------------编程问答-------------------- lz不说清楚,怎么解决啊? --------------------编程问答-------------------- 母版页HTML:(其实暂时什么也没有)
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="EMSMasterPage.master.cs" Inherits="EMSMasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server" style="left: 0px; position: absolute; top: 0px;">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
        </asp:contentplaceholder>
    </form>
</body>
</html>

内容页客户端代码
<%@ Page Language="C#" MasterPageFile="EMSMasterPage.master" AutoEventWireup="true" CodeFile="TestRefresh.aspx.cs" Inherits="TestRefresh" %>

   
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script language="javascript" type="text/javascript" >
     function OpenModalDialog(url, name)
{
    var vReturnValue;
    if(url != null)
    {
        vReturnValue = window.showModalDialog(url, "#1", "dialogHeight: 400px; dialogWidth: 600px; dialogTop: 100px; dialogLeft: 100px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
    }
    else
    {
        alert("No URL passed to open");
    }
    if(vReturnValue != null && vReturnValue == true)
    {
        __doPostBack('<%=Image3.UniqueID%>', "");
        return vReturnValue    
    }
    else
    {   
        return false;
    }
}

    </script>  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
        Width="237px">
        <Columns>
            <asp:BoundField DataField="DEPTNO" HeaderText="DEPTNO" SortExpression="DEPTNO" />
            <asp:BoundField DataField="DNAME" HeaderText="DNAME" SortExpression="DNAME" />
            <asp:BoundField DataField="LOC" HeaderText="LOC" SortExpression="LOC" />
        </Columns>
    </asp:GridView>
    
 
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand='SELECT * FROM "TEST"'>
        </asp:SqlDataSource>
     
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Add" Width="116px" />
        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" />
        <asp:LinkButton ID="Image3" runat="server" OnClick="Image3_Click"></asp:LinkButton>
</asp:Content>

服务器端代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class TestRefresh : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            string script = "javascript:OpenModalDialog('AddDept.aspx', '" + Button2.ID + "');";
            this.Button1.Attributes.Add("onclick", script);
                  }
            }
   
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.GridView1.DataBind();
    }
    protected void Image3_Click(object sender, EventArgs e)
    {
        this.GridView1.DataBind();
    }
}

AddDept.aspx 客户端
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddDept.aspx.cs" Inherits="AddDept" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
   <base target="_self" /> 
  <script language="javascript" type="text/javascript">
    function CloseFormOK()
    {
        window.returnValue = true;
        self.close();
    }
     function CloseFormCancel()
    {
        window.returnValue = false;
        self.close();
    }
    </script> 
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width: 479px; height: 160px">
            <tr>
                <td style="width: 100px">
                    Dept No</td>
                <td style="width: 100px">
                    <asp:TextBox ID="txtDeptNo" runat="server"></asp:TextBox></td>
                <td style="width: 100px">
                </td>
            </tr>
            <tr>
                <td style="width: 100px">
                    Name</td>
                <td style="width: 100px">
                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox></td>
                <td style="width: 100px">
                </td>
            </tr>
            <tr>
                <td style="width: 100px">
                    Location</td>
                <td style="width: 100px">
                    <asp:TextBox ID="txtLoc" runat="server"></asp:TextBox></td>
                <td style="width: 100px">
                </td>
            </tr>
        </table>
    
    </div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand='SELECT * FROM "DEPT"' InsertCommand="INSERT INTO TEST(DEPTNO, DNAME, LOC) VALUES (:DEPTNO, :name, :LOC)">
            <InsertParameters>
                <asp:ControlParameter ControlID="txtDeptNo" Name="deptno" PropertyName="Text" />
                <asp:ControlParameter ControlID="txtName" Name="name" PropertyName="Text" />
                <asp:ControlParameter ControlID="txtLoc" Name="loc" PropertyName="Text" />
            </InsertParameters>
        </asp:SqlDataSource>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" Width="108px" />
    </form>
</body>
</html>
服务器
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class AddDept : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.SqlDataSource1.Insert();
        string script = "<script language='javascript' type='text/javascript'>CloseFormOK();</script>";
        ClientScript.RegisterStartupScript(Page.GetType(), "PopupScript", script);
    }
}


最终的结果是执行了
 protected void Image3_Click(object sender, EventArgs e)
    {
        this.GridView1.DataBind();
    }

但是却不刷新数据表
--------------------编程问答-------------------- 刚才下班了,回来写了个测试程序..大家看下,不访试试,问题怎么解决? --------------------编程问答-------------------- [img=http://photo.store.qq.com/http_imgload.cgi?/rurl2=b0ee1fb650b234eaa917b8fb6ad1ee87308eb35ae4455efbd5dcb54c43aaf2f2d42b4de4ac0c36f5029c9e4cda400147177ac75dc15cfed5a267209d181af82deaea00d543596da65698ec40ce844a7b5c34da02][/img]
点击ADD,弹出对话框AddDept.aspx,输入值10,10,10,点击OK返回到TestRefresh.aspx,最终执行了
protected void Image3_Click(object sender, EventArgs e) 
    { 
        this.GridView1.DataBind(); 
    } 

却gridView1却并没有刷新,可是你点击IMAGE3就可以刷新(可以设置下IMAGE3.TEXT)
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,