locked
Uncaught Syntax Error Invalid or UnExpected token RRS feed

  • Question

  • User-797751191 posted

    Hi

     i have below code 

    <a id="lnkReject" runat="server" title="Reject" class="btn btn-danger btn-xs" onclick='<%# string.Format("editPop(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\");", Eval("Document No_"), Eval("Loc"), Eval("Customer"), Eval("Name"), Eval("Id")) %>'></a>

    onclick="editPop(&quot;IVEUG1-8888-0123&quot;, &quot;HCL1&quot;, &quot;VU00000008&quot;, &quot;VEGESNA RAGHURAMA RAJU
    &quot;, &quot;IND&quot;);"></a>

    Thanks

    Wednesday, September 18, 2019 1:02 PM

All replies

  • User475983607 posted

    The resulting code is encoded.  You'll need to decode the string.

    onclick="editPop('IVEUG1-8888-0123', 'HCL1', 'VU00000008', 'VEGESNA RAGHURAMA RAJU', 'IND');"></a>

    https://docs.microsoft.com/en-us/dotnet/api/system.web.httputility.htmlencode?view=netframework-4.8

    https://docs.microsoft.com/en-us/dotnet/api/system.web.httputility.htmldecode?view=netframework-4.8

    Wednesday, September 18, 2019 1:10 PM
  • User288213138 posted

    Hi jsshivalik,

    According to your description, i can't reproduce your question. but I made demo for you.

    The code:

    <script type="text/javascript">
            function popup(url, width, height) {
                var width = width;
                var height = height;      
                var params = 'width=' + width + ', height=' + height;        
                window.open(url, 'name', params);       
                return false;
            }
        </script>
    
     <a href="#" onclick="<%= Server.HtmlEncode(string.Format("popup(\"{0}\", \"{1}\", \"{2}\");", "https://forums.asp.net/t/2159878.aspx",600,300))%>">Click me</a>

    Best regards,

    Sam

    Friday, September 20, 2019 8:39 AM
  • User-797751191 posted

    Hi Samwu

       Will it work with link button . I want to use link button

    Thanks

    Friday, September 20, 2019 11:30 AM
  • User475983607 posted

    jsshivalik

    Will it work with link button . I want to use link button

    Server.HtmlEncode() fixes the issue in this duplicate thread.   However, you also have a design bug.  Unfortunately, you have not clearly explained the problem you are trying to solve in this or your similar threads.

    Can you explain the design intent?  Are you trying to open a new window or tab with content, open a confirmation modal, open a modal HTML form, maybe something else?

    Also, please provide the editPopup function/method and explain how you intend the code to work.  

    Friday, September 20, 2019 11:44 AM
  • User-797751191 posted

    Hi

    
    
    <a id="lnkReject" runat="server" title="Reject" class="btn btn-danger btn-xs" onclick='<%# string.Format("editPop(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\");", Eval("Document No_"), Eval("Loc"), Eval("Customer"), Eval("Name"), Eval("Id")) %>'></a>
    
    
    
    function editPop(DocumentNo,Loc,Customer,Name,Id) {
                    $("#myModal").modal(); 
                    $("#hdfDocumentNo").val(DocumentNo);
                    $("#hdfLOc").val(Loc);
                    $("#hdfCustomerNo").val(Customer);
                    $("#hdfCustomerName").val(Name);
                    $("#hdfCompany_Id").val(Id);
                }
    
    
    onclick="editPop(&quot;IVEUG1-8888-0123&quot;, &quot;HCL1&quot;, &quot;VU00000008&quot;, &quot;VEGESNA RAGHURAMA RAJU
    &quot;, &quot;IND&quot;);"></a>

    Thanks

    Saturday, September 21, 2019 4:55 AM
  • User475983607 posted

    From some unknown reason you are not following any of the recommendations in this thread or your similar threads. 

    Given your code, I'm guessing you are trying to open a Bootstrap Modal so the user can confirm a delete.  The following is a WORKING example.   Feel free to update the code as needed.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BootstrapModal.aspx.cs" Inherits="WebFormsDemo.BootstrapModal" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous" />
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous" />
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:GridView ID="CustomerDocuments" runat="server" AutoGenerateColumns="False">
                    <Columns>
                        <asp:TemplateField HeaderText="Edit">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <a href="#" 
                                    data-documentno="<%# Eval("DocumentNo") %>" 
                                    data-loc="<%# Eval("LOC") %>" 
                                    data-customerno="<%# Eval("CustomerNo") %>" 
                                    data-customername="<%# Eval("CustomerName") %>" 
                                    data-company_id="<%# Eval("Company_Id") %>" 
                                    data-toggle="modal" 
                                    data-target="#DeleteRecord">
                                    Delete
                                </a>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </div>
    
            <div class="modal fade" id="DeleteRecord" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLabel">New message</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <asp:HiddenField ID="hdfDocumentNo" runat="server" />
                            <asp:HiddenField ID="hdfLOC" runat="server" />
                            <asp:HiddenField ID="hdfCustomerNo" runat="server" />
                            <asp:HiddenField ID="hdfCustomerName" runat="server" />
                            <asp:HiddenField ID="hdfCompany_Id" runat="server" />
                            <div>
                                Doc No: <span id="DocumentNo"></span><br />
                                LOC: <span id="LOC"></span><br />
                                Customer No: <span id="CustomerNo"></span><br />
                                Customer Name: <span id="CustomerName"></span><br />
                                Company Id: <span id="Company_Id"></span><br />
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                            <asp:Button ID="Submit" runat="server" Text="Submit" class="btn btn-primary" OnClick="Submit_Click" />
                        </div>
                    </div>
                </div>
            </div>
        </form>
    
        <div>
            <pre>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            </pre>
        </div>
        
    
        <script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
        <script>
            $('#DeleteRecord').on('show.bs.modal', function (event) {
                var link = $(event.relatedTarget);
    
                var documentno = link.data('documentno');
                var loc = link.data('loc');
                var customerno = link.data('customerno');
                var customername = link.data('customername');           
                var company_id = link.data('company_id');
    
                var modal = $(this);
    
                modal.find('.modal-body #<%=hdfDocumentNo.ClientID%>').val(documentno);
                modal.find('.modal-body #<%=hdfLOC.ClientID%>').val(loc);
                modal.find('.modal-body #<%=hdfCustomerNo.ClientID%>').val(customerno);
                modal.find('.modal-body #<%=hdfCustomerName.ClientID%>').val(customername);
                modal.find('.modal-body #<%=hdfCompany_Id.ClientID%>').val(company_id);
    
                modal.find('.modal-body #DocumentNo').text(documentno);
                modal.find('.modal-body #LOC').text(loc);
                modal.find('.modal-body #CustomerNo').text(customerno);
                modal.find('.modal-body #CustomerName').text(customername);
                modal.find('.modal-body #Company_Id').text(company_id);
            })
        </script>
    </body>
    </html>
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebFormsDemo
    {
        public class CustomerDocument
        {
            public int DocumentNo { get; set; }
            public string LOC { get; set; }
            public int CustomerNo { get; set; }
            public string CustomerName { get; set; }
            public int Company_Id { get; set; }
        }
    
        public partial class BootstrapModal : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    CustomerDocuments.DataSource = GetCustomerDocument();
                    CustomerDocuments.DataBind();
                }
            }
    
            private List<CustomerDocument> GetCustomerDocument()
            {
                List<CustomerDocument> results = new List<CustomerDocument>()
                {
                    new CustomerDocument()
                    {
                        Company_Id = 1,
                        CustomerName = "Customer 1",
                        CustomerNo = 123,
                        DocumentNo = 2,
                        LOC = "LOC 1"
                    },
                    new CustomerDocument()
                    {
                        Company_Id = 50,
                        CustomerName = "Customer 50",
                        CustomerNo = 4444,
                        DocumentNo = 3,
                        LOC = "LOC 2"
                    }
                };
                return results;
            }
    
            protected void Submit_Click(object sender, EventArgs e)
            {
                Label1.Text = $@"You selected 
                    Doc No: {hdfDocumentNo.Value} 
                    LOC: {hdfLOC.Value} 
                    Customer No: {hdfCustomerNo.Value} 
                    Customer Name: {hdfCustomerName.Value} 
                    Company Name: {hdfCompany_Id.Value}";
            }
        }
    }

    Also, please read the following Bootstrap reference documentation.

    https://getbootstrap.com/docs/4.0/components/modal/

    Saturday, September 21, 2019 1:10 PM
  • User288213138 posted

    Hi jsshivalik,

    onclick="editPop(&quot;IVEUG1-8888-0123&quot;, &quot;HCL1&quot;, &quot;VU00000008&quot;, &quot;VEGESNA RAGHURAMA RAJU
    &quot;, &quot;IND&quot;);"></a>

    Is this the result of browser rendering?

    Here's a similar question you can use as a reference: https://stackoverflow.com/a/37858434

    I guess the problem is caused by using " " render. so please try to change "" to ' ' .

    If you also can't solve the problem, please post your full aspx code.

    Best regards,

    Sam

    Monday, September 23, 2019 12:51 PM