Open different popup window based on condition using JavaScript

narasiman
 
on Feb 04, 2018 11:48 PM
1454 Views

I am redirect page using open window in c# My gridview as follows

  Date       Place      In Time       Out Time       Hours      View

  1/1/2018    Delhi     9.30          6.30          9.00      View Details

  8/1/2018    Delhi     10.00         7.00          9.00      View Details

When i click the first row View Details in the gridview. i want to redirect to page1.aspx Similarly when i click the second row View Details in the gridview. i want to redirect to page2.aspx.

for that i written a code as follows

<script type="text/javascript">
    function openWindow(Date) {
        window.open('Page1.aspx?Date=' + Date, 'open_window', ' width=450, height=300, left=0, top=0'); 
    }

    function openWindow(Date) {
        window.open('Page2.aspx?Date=' + Date, 'open_window', ' width=450, height=300, left=0, top=0');  
    }

</script>
<asp:GridView ID="GridView1" runat="server" />
    <Columns>
        <asp:BoundField DataField="Date" HeaderText="Date" />  
        <asp:BoundField DataField="Place" HeaderText="Place" />  
        <asp:BoundField DataField="InTime" HeaderText="InTime" />  
        <asp:BoundField DataField="OutTime" HeaderText="OutTime" />
        <asp:BoundField DataField="WorkingHours" HeaderText="WorkingHours" />
        <asp:TemplateField HeaderText="View">
            <ItemTemplate>
                <a href="#" onclick='openWindow("<%# Eval("Date") %>");'>View Details</a> 
            </ItemTemplate>
        </asp:TemplateField>
   </Columns>
</asp:GridView>

what is the mistake in my above code.

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
nagaraju60
 
on Feb 05, 2018 12:13 AM
on Feb 05, 2018 12:15 AM

Dear @narasiman,

asper your code you are call the same function name two times. so the view button redirected to second function. please modify secondfunction name or use the validations for single function name.

<script type="text/javascript">
    function openWindow(Date) {
        window.open('Page1.aspx?Date=' + Date, 'open_window', ' width=450, height=300, left=0, top=0');
    }
 
    function openWindow1(Date) {
        window.open('Page2.aspx?Date=' + Date, 'open_window', ' width=450, height=300, left=0, top=0'); 
    }
</script>

or

<script type="text/javascript">
    function openWindow(Date) {
        if(Validation as per your requirement)
        {
             window.open('Page1.aspx?Date=' + Date, 'open_window', ' width=450, height=300, left=0, top=0');
        }   
        else
        {
             window.open('Page2.aspx?Date=' + Date, 'open_window', ' width=450, height=300, left=0, top=0'); 
         }
    }  
</script>