I have several textboxes for user input and button to save record. Before finally insert records to DB, in C# button click action I'd like to suggest user to fill some important textboxes using javascript function with confirm dialog. If user choose yes code should break and focus textbox. If not, code should continue and insert record. That's my goal. But, JS function is not starting even condition is true. JS function starts only if there si return; in the end of C# JS call. Here is my code:
protected void savenew_Click(object sender, EventArgs e)
{ if (string.IsNullOrEmpty(arr.Text)) { ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('Missing arr..');", true); arr.Focus(); return; }
// HERE IS PROBLEM:
if (string.IsNullOrEmpty(telnr.Text))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "corectyesno()", true); return;
}
try
{
SqlCommand MyCommand = new SqlCommand( etc...
//and JS function:
function corectyesno()
{
if (confirm('Do you want to proceed ?')) {
return true;
}
else {
return false;
}
}
My language is not english so please excuse me for my grammar. Next, programming is my hobby so... Thanks to everyone who can help me and suggest better approach.