Answered by:
why my code is not working when move to cloud hosting

Question
-
User-807418713 posted
hello
In local this below code works fine
<script type="text/javascript"> var data = []; $(document).ready(function () { $('.csschange').change(function (e) { var ReqBy = document.getElementById('<%=DropDownList1.ClientID%>').value; var ReqDate = document.getElementById('<%=TextBox2.ClientID%>').value; var ReqNo = document.getElementById('<%=TextBox3.ClientID%>').value; var ChemicalName = document.getElementById('<%=D1.ClientID%>').value; var Qty = document.getElementById('<%=TextBox1.ClientID%>').value; var item = { ReqBy: document.getElementById('<%=DropDownList1.ClientID%>').value, ReqDate: document.getElementById('<%=TextBox2.ClientID%>').value, ReqNo: document.getElementById('<%=TextBox3.ClientID%>').value, ChemicalName: document.getElementById('<%=D1.ClientID%>').value, Qty: document.getElementById('<%=TextBox1.ClientID%>').value, }; data.push(item); item.index = data.length -1; // $("#ctl00_ContentPlaceHolder1_GridView1 tbody").append("<tr data-index='" + (data.length-1) + "'> <td>" + $('#ctl00_ContentPlaceHolder1_TextBox11').val() + "</td><td>" + $('#ctl00_ContentPlaceHolder1_TextBox10').val() + "</td>" + "<td><input type='button' value='Delete' /></td>" + "</tr>") $("#ctl00_ContentPlaceHolder1_GridView1 tbody").append( "<tr data-index='" + (data.length-1) + "'><td>" + document.getElementById('<%=DropDownList1.ClientID%>').value + "</td><td>" + document.getElementById('<%=TextBox2.ClientID%>').value + "</td><td>" + document.getElementById('<%=TextBox3.ClientID%>').value + "</td><td>" + document.getElementById('<%=D1.ClientID%>').value + "</td><td>" +document.getElementById('<%=TextBox1.ClientID%>').value + "</td>" + "<td><input type='button' value='Delete' /></td>" + "</tr>") $("#ctl00_ContentPlaceHolder1_GridView1 tbody tr:last input").click(function () { $(this).parent("td").parent("tr").remove(); var index = $(this).parent("td").parent("tr").data("index"); data = data.filter(function (ele) { if (ele.index == index) { return false; } return true; }) }) // $('#ctl00_ContentPlaceHolder1_DropDownList3 option:first').prop("selected",true); // $('#ctl00_ContentPlaceHolder1_TextBox10').val(""); // $('#ctl00_ContentPlaceHolder1_TextBox11').val(""); }); $("#Button2").click(function () { $.ajax({ type: 'POST', contentType: "application/json; charset=utf-8", url: 'ChemRequest_Internal.aspx/InsertData', data: JSON.stringify({myModels:data}), success: function (e) { alert("Requested Sucessfully..."); location.reload(true); }, error: function (e) { alert("Error In Page Please Contact Admin..."); } }); }) }); </script>
the same page i upload in my cloud server its not working whats the issues
Thursday, March 11, 2021 9:41 AM
Answers
-
User475983607 posted
This is a design bug. You hardcode IDs that are dynamically generated. You'll need to fix the design. I would use CSS classes and/or data- attributes. You can also stick with using the ClientID like you are doing with the other server controls.
$("#<%=GridView1.ClientID%> tbody tr:last input").click(function () {
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 11, 2021 2:37 PM -
User753101303 posted
Try something similar to what you have done already ie maybe something such as:
$('#<%=GridView1.ClientID%> tbody").append(etc...
It seems that you are not using the same ..NET version locally and on your hsoting service. if possible I prefer to always try to use the same version on both sides.
Before trying the fix try perhaps F12 Console n your browser to see if you could have located this problem by yourself more easily than by reading your code.
Recently I saw for example a code snippet with at least 5 or 6 possible errors which make even impossible to guess right about which problem happens unless the OP takes the couple of minutes needed to find and tell us that.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 11, 2021 2:40 PM
All replies
-
User753101303 posted
Hi,
"Not working" that is? It shows "Error In page Please Contact Admin..." or use https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools to find what actually happens.
For now my guess is that the hardcoded control name is perhaps not generated the same way?
Thursday, March 11, 2021 2:00 PM -
User-807418713 posted
Hello PatriceSc
in local its showing
ctl00_ContentPlaceHolder1_GridView1
in server its not the same
ContentPlaceHolder1_GridView1
how to pass this in perfect manner
Thursday, March 11, 2021 2:26 PM -
User475983607 posted
This is a design bug. You hardcode IDs that are dynamically generated. You'll need to fix the design. I would use CSS classes and/or data- attributes. You can also stick with using the ClientID like you are doing with the other server controls.
$("#<%=GridView1.ClientID%> tbody tr:last input").click(function () {
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 11, 2021 2:37 PM -
User753101303 posted
Try something similar to what you have done already ie maybe something such as:
$('#<%=GridView1.ClientID%> tbody").append(etc...
It seems that you are not using the same ..NET version locally and on your hsoting service. if possible I prefer to always try to use the same version on both sides.
Before trying the fix try perhaps F12 Console n your browser to see if you could have located this problem by yourself more easily than by reading your code.
Recently I saw for example a code snippet with at least 5 or 6 possible errors which make even impossible to guess right about which problem happens unless the OP takes the couple of minutes needed to find and tell us that.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 11, 2021 2:40 PM -
Thursday, March 11, 2021 3:14 PM