从弹出窗口刷新父页面时出现问题 [英] Problem refreshing parent page from a popup window

查看:66
本文介绍了从弹出窗口刷新父页面时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





刷新我的父页面时出现问题,如果我更新数据,我父级的gridview正确刷新,如果我插入网格不会刷新。我尝试了很多教程,没有解决任何问题。



这是我的代码。

父级:parametros.aspx

孩子:talhao.aspx



我用javascript打开弹出的孩子。

父asp:



Hi,

I have a problem refreshing my parent page, if i update data the gridview of my parent refreshes correctly, if i insert the grid wont refresh. I´ve tried a lot of tutorials and nothing resolves.

Here is my code.
Parent: parametros.aspx
child:talhao.aspx

I use javascript to open the popup child.
parent asp:

<head runat="server">
    <title></title>
    <script>
        function openWindow(id) {
            window.open('talhao.aspx?id_talhao=' + id, 'open_window', ' with=640, height=300, left=300, top=200');
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id_talhao" DataSourceID="SqlDataSource1" Width="207px">
            <Columns>
                <asp:BoundField DataField="id_talhao" HeaderText="id_talhao" InsertVisible="False" ReadOnly="True" SortExpression="id_talhao" />
                <asp:BoundField DataField="descricao" HeaderText="descricao" SortExpression="descricao" />
                <asp:TemplateField HeaderText="Descrição" SortExpression="descricao">
                    <ItemTemplate>
                        <a href="#" ><%#Eval("descricao")%></a>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Novo Talhão" OnClientClick="openWindow(0)" />
        <br />
       
    
    </div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CMSMAConnectionString %>" SelectCommand="SELECT * FROM [cem_talhao]"></asp:SqlDataSource>
    </form>
</body>





子asp代码:



child asp code:

<body>
    <form id="form1" runat="server">
    <div id="mainWrapper">
        <asp:Table ID="Table1" runat="server" Height="18px" Width="432px" BorderStyle="None">
            <asp:TableRow runat="server" BorderStyle="None">
                <asp:TableCell runat="server" BorderStyle="None">
                    <asp:Label ID="lbl_talhao" runat="server" Text="ID Talhão: "></asp:Label>
                </asp:TableCell>
                <asp:TableCell runat="server" RowSpan="4" BorderStyle="None" HorizontalAlign="Center" >
                    <asp:Label ID="lbl_ID" runat="server" Text="Label" Visible="false"></asp:Label>
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow runat="server" BorderStyle="None">
                <asp:TableCell runat="server" BorderStyle="None">
                    <asp:Label ID="lbl_desc" runat="server" Text="Descrição:"></asp:Label>
                    <asp:TextBox ID="txt_desc" runat="server" Width="316px"></asp:TextBox>
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow runat="server" BorderStyle="None">
                  <asp:TableCell runat="server" BorderStyle="None">
                      <asp:Button ID="btn_save" runat="server" Text="Gravar" Font-Bold="True" CssClass="guardar"/>
                  </asp:TableCell>  
                
            </asp:TableRow>
        </asp:Table>
  
    
    </div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CMSMAConnectionString %>" SelectCommand="SELECT * FROM [cem_talhao] WHERE ([id_talhao] = @id_talhao)" InsertCommand="INSERT INTO cem_talhao(descricao) VALUES (@descricao)" UpdateCommand="UPDATE cem_talhao SET descricao = @descricao WHERE (id_talhao = @id_talhao)">
            <InsertParameters>
                <asp:ControlParameter ControlID="txt_desc" Name="descricao" PropertyName="Text" />
            </InsertParameters>
            <SelectParameters>
                <asp:QueryStringParameter Name="id_talhao" QueryStringField="id_talhao" Type="Int32" />
            </SelectParameters>
            <UpdateParameters>
                <asp:ControlParameter ControlID="txt_desc" Name="descricao" PropertyName="Text" />
                <asp:QueryStringParameter Name="id_talhao" QueryStringField="id_talhao" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </form>
</body>





子vb代码:



child vb code:

Dim desc, id_talhao As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If Request.QueryString("id_talhao") <> "0" Then 'update
                Dim dv As DataView = DirectCast(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
                Dim drv As DataRowView = dv(0)
                desc = drv("descricao").ToString
                id_talhao = drv("id_talhao").ToString
                lbl_talhao.Text += id_talhao
                txt_desc.Text = desc
            Else 'insert

            End If
        End If
    End Sub


    Private Sub btn_save_Click(sender As Object, e As EventArgs) Handles btn_save.Click
        If txt_desc.Text.Trim <> "" Then
            If Request.QueryString("id_talhao") <> "0" Then 'update
                If txt_desc.Text <> desc Then
                    SqlDataSource1.Update()
                    Response.Write("<script>window.close(); window.opener.location.reload(false);</script>")
                    Response.End()
                End If
            Else 'insert
                SqlDataSource1.Insert()
                Response.Write("<script>window.close(); window.opener.location.reload(false);</script>")
                Response.End()
            End If
        End If
    End Sub





感谢您的帮助。



Thanks for your help.

推荐答案

ConnectionStrings:CMSMAConnectionString%> SelectCommand = SELECT * FROM [cem_talhao] > < / asp:SqlDataSource >
< / form >
< / body >
ConnectionStrings:CMSMAConnectionString %>" SelectCommand="SELECT * FROM [cem_talhao]"></asp:SqlDataSource> </form> </body>





儿童asp代码:



child asp code:

<body>
    <form id="form1" runat="server">
    <div id="mainWrapper">
        <asp:Table ID="Table1" runat="server" Height="18px" Width="432px" BorderStyle="None">
            <asp:TableRow runat="server" BorderStyle="None">
                <asp:TableCell runat="server" BorderStyle="None">
                    <asp:Label ID="lbl_talhao" runat="server" Text="ID Talhão: "></asp:Label>
                </asp:TableCell>
                <asp:TableCell runat="server" RowSpan="4" BorderStyle="None" HorizontalAlign="Center" >
                    <asp:Label ID="lbl_ID" runat="server" Text="Label" Visible="false"></asp:Label>
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow runat="server" BorderStyle="None">
                <asp:TableCell runat="server" BorderStyle="None">
                    <asp:Label ID="lbl_desc" runat="server" Text="Descrição:"></asp:Label>
                    <asp:TextBox ID="txt_desc" runat="server" Width="316px"></asp:TextBox>
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow runat="server" BorderStyle="None">
                  <asp:TableCell runat="server" BorderStyle="None">
                      <asp:Button ID="btn_save" runat="server" Text="Gravar" Font-Bold="True" CssClass="guardar"/>
                  </asp:TableCell>  
                
            </asp:TableRow>
        </asp:Table>
  
    
    </div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%


ConnectionStrings:CMSMAConnectionString %>\" SelectCommand=\"SELECT * FROM [cem_talhao] WHERE ([id_talhao] = @id_talhao)\" InsertCommand=\"INSERT INTO cem_talhao(descricao) VALUES (@descricao)\" UpdateCommand=\"UPDATE cem_talhao SET descricao = @descricao WHERE (id_talhao = @id_talhao)\">
<InsertParameters>
<asp:ControlParameter ControlID=\"txt_desc\" Name=\"descricao\" PropertyName=\"Text\" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name=\"id_talhao\" QueryStringField=\"id_talhao\" Type=\"Int32\" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter ControlID=\"txt_desc\" Name=\"descricao\" PropertyName=\"Text\" />
<asp:QueryStringParameter Name=\"id_talhao\" QueryStringField=\"id_talhao\" />
</UpdateParameters>
</asp:SqlDataSource>
< /form>
</body>
ConnectionStrings:CMSMAConnectionString %>" SelectCommand="SELECT * FROM [cem_talhao] WHERE ([id_talhao] = @id_talhao)" InsertCommand="INSERT INTO cem_talhao(descricao) VALUES (@descricao)" UpdateCommand="UPDATE cem_talhao SET descricao = @descricao WHERE (id_talhao = @id_talhao)"> <InsertParameters> <asp:ControlParameter ControlID="txt_desc" Name="descricao" PropertyName="Text" /> </InsertParameters> <SelectParameters> <asp:QueryStringParameter Name="id_talhao" QueryStringField="id_talhao" Type="Int32" /> </SelectParameters> <UpdateParameters> <asp:ControlParameter ControlID="txt_desc" Name="descricao" PropertyName="Text" /> <asp:QueryStringParameter Name="id_talhao" QueryStringField="id_talhao" /> </UpdateParameters> </asp:SqlDataSource> </form> </body>





child vb code:



child vb code:

Dim desc, id_talhao As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If Request.QueryString("id_talhao") <> "0" Then 'update
                Dim dv As DataView = DirectCast(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
                Dim drv As DataRowView = dv(0)
                desc = drv("descricao").ToString
                id_talhao = drv("id_talhao").ToString
                lbl_talhao.Text += id_talhao
                txt_desc.Text = desc
            Else 'insert

            End If
        End If
    End Sub


    Private Sub btn_save_Click(sender As Object, e As EventArgs) Handles btn_save.Click
        If txt_desc.Text.Trim <> "" Then
            If Request.QueryString("id_talhao") <> "0" Then 'update
                If txt_desc.Text <> desc Then
                    SqlDataSource1.Update()
                    Response.Write("<script>window.close(); window.opener.location.reload(false);</script>")
                    Response.End()
                End If
            Else 'insert
                SqlDataSource1.Insert()
                Response.Write("<script>window.close(); window.opener.location.reload(false);</script>")
                Response.End()
            End If
        End If
    End Sub





Thanks for your help.



Thanks for your help.


Hi, i resolved the problem making the bind of the data on the parent page load.



Hi, i resolved the problem making the bind of the data on the parent page load.

Public Class parametros
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        GridView1.DataBind()
    End Sub  
End Class


这篇关于从弹出窗口刷新父页面时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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