locked
how to open popup on click of linkbutton with parameters in c# RRS feed

  • Question

  • User-797751191 posted

    Hi

      I am trying below code but it is giving error - Uncaught Syntax Error Invalid or UnExpected token

    onclick='<%# string.Format("editPop(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\");", Eval("No"), Eval("Location"), Eval("Id"), Eval("Name"), Eval("CId")) %>'>

    Thanks

    Thursday, September 19, 2019 1:21 PM

All replies

  • User475983607 posted

    You asked a similar question.  As explained in your other thread, the framework automatically encodes string to protect your code.  

    However, your approach will still not work because a LinkButton is a server control and the onclick attribute wires to a server side event handler.  You should use a standard HTML link rather than a LinkButton.

    <a href="#" onclick="<%= Server.HtmlEncode(string.Format("editPop(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\");", 1, "Location", 234, "Name", 567))%>">
        Click me
    </a>
    <script>
        function editPop(no, location, id, name, cid) {
            var data = {
                no: no,
                location: location,
                id: id,
                name: name,
                cid: cid
            };
            console.log(data);
            return false;
        }
    </script>

    LinkButton

        <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="<%# Server.HtmlEncode(string.Format("editPop(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\");", Eval("No"), Eval("Location"), Eval("Id"), Eval("Name"), Eval("CId"))) %>"# >">
            LinkButton
        </asp:LinkButton>

    Thursday, September 19, 2019 1:48 PM
  • User-797751191 posted

    Hi mgebhard

      Then how i will access values in code behind if anchor tag is used. If u can help me according to my code.

    <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="<%# Server.HtmlEncode(string.Format("editPop(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\");", Eval("No"), Eval("Location"), Eval("Id"), Eval("Name"), Eval("CId"))) %>"# >">
            LinkButton
        </asp:LinkButton>

    Thanks

    Thursday, September 19, 2019 3:41 PM
  • User475983607 posted

    Then how i will access values in code behind if anchor tag is used. If u can help me according to my code.

    You'll need to explain what you are trying to do as the code shown is not enough to understand your design intent.  You can certifiably replace OnClientClient click with OnClick but doing so will throw an compiler error. 

    As for using an anchor tag to run code behind, the standard pattern is invoking a jQuery/AJAX, JavaScript/fetch, using JavaScript to submit the form, or using JavaScript to click a button.  

    Thursday, September 19, 2019 5:52 PM
  • User288213138 posted

    Hi jsshivalik,

    jsshivalik

    Uncaught Syntax Error Invalid or UnExpected token

    According to your description, i can't reproduce your question.

    Can you show me your aspx code?

    jsshivalik

    Eval("No"), Eval("Location"), Eval("Id"), Eval("Name"), Eval("CId")

    And please post the data that you fill the link. i need more information to reproduce your question

    Best regards,

    Sam

    Friday, September 20, 2019 8:08 AM