locked
Send Parameter to Javascript function from ASP Net Button in ListView RRS feed

  • Question

  • User1228272764 posted

    Hi

    I have condition, wich every button in Listview should be produce dynamicaly depends number of ListView Rows. The button shold display popup when clicked and at the same time sending parameter to Javascript function. This is how my code goes : 

    This is my Form 

        <form id="form1" runat="server">
    <%--    <div>
            <asp:Button ID="BtnPop" runat="server" Text="Pop Me Up" OnClientClick="showModalPopUp()" />
        </div>--%>
        <div id = "divBackground" style="; z-index: 999; height: 100%; width: 100%; top: 0; left:0; background-color: Black; filter: alpha(opacity=60); opacity: 0.6; -moz-opacity: 0.8;display:none">
    
        </div>
        <div>
    	        <asp:SqlDataSource ID="SqlDataIzin" runat="server"
    	            ConnectionString="<%$ ConnectionStrings:MyConnCloudDnet2 %>"
    			    SelectCommand="SELECT TOP 3 * FROM Data_izin_header;"
    			    ProviderName="<%$ ConnectionStrings:MyConnCloudDnet2.ProviderName %>">
    	        </asp:SqlDataSource>          
                <asp:ListView ID="ListView1" DataSourceID="SqlDataIzin"  runat="server">
                    <LayoutTemplate>
                        <table>
                            <tr>
                                <td>Nama</td>
                            </tr>
                            <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
                        </table>
                    </LayoutTemplate>
                    <ItemTemplate>
                        <tr>
                            <td><%#Eval("IZIN_NAMA")%></td>   
                            <td><asp:Button ID="BtnPop" runat="server" Text="Pop Me Up" OnClientClick="showModalPopUp()" /></td>    
                        </tr>
                    </ItemTemplate>
                </asp:ListView>
        </div>
        </form>

    This is my script on Head tag of my page

    <script type = "text/javascript">
        var popUpObj;
        function showModalPopUp(id)
        {
        popUpObj=window.open("PopUp.aspx?id=?",
        "ModalPopUp",
        "toolbar=no," +
        "scrollbars=no," +
        "location=no," +
        "statusbar=no," +
        "menubar=no," +
        "resizable=0," +
        "width=500," +
        "height=500," +
        "left = 90," +
        "top=700"
        );
        popUpObj.focus();
        LoadModalDiv();
        }
    
    </script>
    <script type = "text/javascript">
        function LoadModalDiv()
        {
            var bcgDiv = document.getElementById("divBackground");
            bcgDiv.style.display="block";
        }
    </script>
    <script type = "text/javascript">
         function HideModalDiv()
         {
            var bcgDiv = document.getElementById("divBackground");
            bcgDiv.style.display="none";
         }
    </script>

    the main problem is, how could we pass parameter from button click event and use it as input for URLString ? 

    OnClientClick="showModalPopUp(<%#Eval("IZIN_NAMA")%>)"

    i want to send related eval value as a parameter for javascript function

    this should be my main problem :

    popUpObj=window.open("PopUp.aspx?id=?",

    when i tried this, it throw undefined value :

    popUpObj=window.open("PopUp.aspx?id="+id+"",

    do you have any suggestions?

    Tuesday, April 2, 2019 3:09 AM

Answers

  • User1228272764 posted

    done by this code : 

    <td><asp:Button ID="BtnPop" runat="server" Text="Pop Me Up" OnClientClick='<%# Eval("IZIN_NAMA", "showModalPopUp(\"{0}\")")%>' /></td>  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 2, 2019 4:07 AM