I am currently faced with integrating legacy code written in JavaScript and C#. I need to write a new piece of code that will determine whether the OnClick event should fire based on certain conditions. My approach involves checking these conditions within the OnClientClick function. Despite trying various methods found on the Internet, none seem to be effective. As someone who is still learning JavaScript and C#, some of the solutions are difficult for me to grasp. For example, does setting OnClientClick="return confirm ('This will delete the report. Continue?'); return false; " mean that it always returns before executing "return false"?
Below are snippets of my existing codes:
aspx file:
<div id="searchBtn"><asp:LinkButton ID="SearchButton" OnClientClick="return SetInputString(); return false;" OnClick="SearchClick" ValidationGroup="search" runat="server"><img src="images/btn_search.jpg" alt="検索" /></asp:LinkButton></div>
js file:
function SetInputString() {
var textbox = document.getElementById("textForm");
var inputString = document.getElementById("inputString");
clearNonInteractiveTimer();
inputString.value = textbox.value;
if (/^[0-9]{6}$/.test(inputString.value)) {
EvaluateEnteredSearch(inputString.value);
return false;
} else {
return true;
}
}
cs file:
public void SearchClick(object sender, EventArgs e){
...
}