In the table, I have a list of users with "update" and "delete" links added at the end of each line. To enable this functionality, I implemented a JavaScript function that captures the user ID, sets another field to "true," and inserts these values into a form with two hidden fields. The function then triggers a submit operation to the ASP.NET server.
Upon checking, the submit operation works fine (verified using respons.write("-----"))
However, I am facing challenges in recognizing the post when activating submit() with JavaScript. I tried using the value of the hidden field, but it doesn't seem to capture it, leading to the skipping of the if statement...
Another issue I encountered during debugging is that the browser (IE9) throws an error when the submit() function is triggered...
The code for the list of users:
foreach(var row in db.Query(displayExperts,nameOfExpert))
{
<tr>
<td class="dispExpertActScreen">@row.ExpertID</td>
<td class="dispExpertActScreen">@row.name</td>
<td class="dispExpertActScreen">@row.password</td>
<td class="dispExpertActScreen">@row.allowBonds</td>
<td class="dispExpertActScreen">@row.allowStocks</td>
<td class="dispExpertActScreen">@row.allowExchangeTraded</td>
<td class="dispExpertActScreen">@row.allowMutualFund</td>
<td class="dispExpertActScreen"><a href="#" onclick="expertToDelete('@row.ExpertID') ;return false;" style="color: #b04e4e">update</a></td>
<td class="dispExpertActScreen"><a href="#" onclick="expertToDelete('@row.ExpertID') ;return false;" style="color: #b04e4e">delete</a></td>
</tr>
}
The form:
<form method="post" name="deleteExpert" style="font-size: medium; margin-top: 10%" dir="rtl">
<input type="hidden" name="expertID" id="expertID" value="">
<input type="hidden" name="txtJavascriptMode" id="txtJavascriptMode" value="">
</form>
The JavaScript function:
<script>
function expertToDelete(expertID) {
document.getElementById('expertID').value = expertID;
document.getElementById('txtJavascriptMode').value = 'true';
document.getElementById('deleteExpert').submit();
}
</script>
The ASP.NET code:
@{
var db = Database.Open("MyProjectSite");
var display="no";
var displayExperts="";
var nameOfExpert="";
var category="";
if(IsPost)
{
if(Request.Form["ExpertButton"]== "search")// this is by button!!!
{
some code.....
}
Response.Write("----");
if(Request.Form["txtJavascriptMode"] == "true")
{
var id=Request.Form["expertID"];
var deleteQuery="DELETE FROM InvestmanExperts WHERE ExpertID=@0";
db.Execute(deleteQuery,id);
}
}
db.Close();
}
There's something strange when I include this line:
Response.Write("----"+Request.Form["txtJavascriptMode"]);
Prior to:
if(Request.Form["txtJavascriptMode"] == "true");
The website's indentation appears off, yet the delete user function works correctly, why?
Thank you...