Click here to Skip to main content
15,442,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Friends,

I am facing a problem in asp.net, C#.net and javascript programming.

Please go on following link to see video first
help - YouTube[^]

Problem

my problem is that, I created a webpage in asp.net where i'm fetching some url from database with a Button and opening these url links in child window, and want to get response from child window that it is closed by user or "timeout close" as we defined. we use the javascript to open and close child window, on the behalf of response of child window i'm making some updates on parent window but i'm unable to get this response.

What I have tried:

I've tried Gridview & repeater with javascript.

In gridview with javascript, i faced a problem that is we fetched the url links from database, when we pass the url link on calling of javascript function(argument) then it take url and open that link in another child window but the Script doesn't work to close on proper given time, if we pass a specific url then it will work properly and change the status of button. And if the user close the window forcefully and then it should not be change the status of button, but it changed the status.

When we use the Repeater with script, it is close the window on time but if user close the child window then it is also change the status of button, and one most problem is that it store the all button status at the first click.

we want the solution,
1.) Child window's close button should be disable.
2.)Button status should be disable exact to only single button which is in working.
3.)Child window should be closed on expected time or if user close the child then there should not be change the button status.

My Code is given below here:

links.aspx Page code

ASP.NET
    <form id="form1" runat="server">
<table class="table table-striped table-bordered table-hover dataTable" style="background-color: #EAEAEA;
            border: 1; height: 250px; width: 1048px">
            <asp:Repeater ID="rptHotItems" runat="server" OnItemDataBound="rptHotItems_ItemDataBound">
                <HeaderTemplate>
                    <thead>
                        <tr>
                            <th>
                                Sr.No
                            </th>
                            <th>
                                ADD Name
                            </th>
                            <th>
                                ADD URL
                            </th>
                            <th>
                                Status/Action
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <%-- <td>
                            <asp:Label ID="lblSno" runat="server" Text='<%#Container.ItemIndex+1 %>'></asp:Label>
                        </td> --%>
                        <td>
                            <asp:Label ID="lbl_id" runat="server" Text='<%#Eval("work_id") %>'></asp:Label>
                        </td>
                        <td>
                            <asp:Label ID="Ads_name" runat="server" Text='<%#Eval("Ads_name") %>'></asp:Label>
                        </td>
                        <td>
                            <asp:Label ID="lbl_url" runat="server" Text='<%#Eval("Ads_url") %>'></asp:Label>
                        </td>
                        <%--  <td><asp:Button ID="Button1" runat="server" Text="Button"   OnClientClick="stopCount();" /></td>--%>
                        <td>
                            <asp:Button ID="Addbutton" class='<%#Eval("Ads_url") %>' runat="server" ForeColor="white"
                                Text="Pending" BackColor="red" />
                        </td>
                </ItemTemplate>
            </asp:Repeater>
        </table>
        <asp:HiddenField ID="hdncolorval" runat="server" />
    </div>
    <center><asp:Button ID="btnsubmit" runat="server" Text="Submit" 
            onclick="btnsubmit_Click1" /></center>
</form>



In above code, we just showing the url text and giving link on button that open child window in given below javascript code show that how it is working. it opens the url(child) window and the change the button status with color(Red/green or Pending/Clicked).



javascript code on links.aspx

JavaScript
function Showpopup(crlid, link) {

    popup_window = window.open(link, "List", "toolbar=no, location=no,status=yes,menubar=no,scrollbars=yes,resizable=no, width=900,height=500,left=430,top=100");
    popup_window.focus();
    function test() {
        setTimeout(function () {
            document.getElementById(crlid).value = "Clicked";
            document.getElementById(crlid).style.background = "green";
            document.getElementById(crlid).disabled = true;
            popup_window.close();

        }, 15000);


        document.getElementById(crlid).style.background = "red";
        document.getElementById(crlid).disabled = true;

    }
    test();
    window.onbeforeunload = function (e) {
        window.parent.functonToCallBeforeThisWindowCloses();
    };
    function test1() {
        document.getElementById(crlid).style.background = "red";
        document.getElementById(crlid).disabled = true;
    }
}



links.aspx.cs Code

C#
protected void rptHotItems_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Button Addbutton = (Button)e.Item.FindControl("Addbutton");
            Label lbl_url = (Label)e.Item.FindControl("lbl_url");
                    Addbutton.Attributes.Add("onclick", "javascript:Showpopup('" + Addbutton.ClientID + "', '" + lbl_url.Text + "');return false;");
                con.Close();
            }  
    }
}


In the above code it handle the Buttons.

The Code Project Open License (CPOL) is intended to provide developers who choose to share their code with a license that protects them and provides users of their code with a clear statement regarding how the code can be used.

The CPOL is our gift to the community. We encourage everyone to use this license if they wish regardless of whether the code is posted on CodeProject.com.
Posted
Updated 18-Jan-17 10:07am
v3
Comments
Richard Deeming 18-Jan-17 15:33pm     CRLF
"Child window's close button should be disable." Nope. There is no way for Javascript to open a popup window and prevent it from being closed. If there was, every phishing, malware, and tech support scam site would be using it for nefarious purposes.
Y0Y0@nK!Y 19-Jan-17 0:46am    
Mr. Deeming, firstly just see the video & then talk
Richard Deeming 19-Jan-17 8:27am    
I don't need to watch a video to tell you that disabling the "close" button in a child window opened from Javascript is impossible.
Y0Y0@nK!Y 19-Jan-17 11:30am    
Nothing is impossible sir, if you have lack of knowledge, so it's your fault.
Richard Deeming 19-Jan-17 11:35am     CRLF
Plenty of things are impossible, often for security reasons. It doesn't matter how much you "need" this feature; if it were possible, it would be a security risk. Therefore, it's not possible. Even if you found a hack to make it work in a single browser, that security vulnerability would be patched pretty quickly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900