Hello,
I have a textbox and button . when I click the button, it should check if the record related to textbox is in the database, and if not, it should pop up the message and ask if we want to add the record to database or not. we get yes/no from the pop up and do chain of events accordingly.
need to do something like
button_click
{
check if record exists
if not exists
ask for confirmation and
add if the confirmation is yes.
}
I have javacript code in .net
private void jsConfirmAdd()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script language=\"javascript\" type=\"text/javascript\">" + Environment.NewLine);
sb.Append("function ConfirmLoanAdd()" + Environment.NewLine);
sb.Append("{" + Environment.NewLine);
//sb.Append(" var confirm=window.confirm('This Loan doesnt exist.Do you want to add?');" + Environment.NewLine);
sb.Append("if (confirm('This Loan doesnt exist.Do you want to add?'))" + Environment.NewLine);
sb.Append("{" + Environment.NewLine);
sb.Append("return true;" + Environment.NewLine);
sb.Append("}" + Environment.NewLine);
sb.Append("else" + Environment.NewLine);
sb.Append("{" + Environment.NewLine);
sb.Append("return false;" + Environment.NewLine);
sb.Append("}" + Environment.NewLine);
sb.Append("}" + Environment.NewLine);
sb.Append("</script>" + Environment.NewLine);
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "validation", sb.ToString());
btnSearch.OnClientClick = "return ConfirmLoanAdd()";
}
and I have btnclick event
at what point do i add value to onclientclick so that message box in above function pops up?
In other words do click and onclientclick go together. By the time i want to call the js function, i already clicked the button.
Please advice the better way to do this.
Thanks
I have a textbox and button . when I click the button, it should check if the record related to textbox is in the database, and if not, it should pop up the message and ask if we want to add the record to database or not. we get yes/no from the pop up and do chain of events accordingly.
need to do something like
button_click
{
check if record exists
if not exists
ask for confirmation and
add if the confirmation is yes.
}
I have javacript code in .net
private void jsConfirmAdd()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script language=\"javascript\" type=\"text/javascript\">" + Environment.NewLine);
sb.Append("function ConfirmLoanAdd()" + Environment.NewLine);
sb.Append("{" + Environment.NewLine);
//sb.Append(" var confirm=window.confirm('This Loan doesnt exist.Do you want to add?');" + Environment.NewLine);
sb.Append("if (confirm('This Loan doesnt exist.Do you want to add?'))" + Environment.NewLine);
sb.Append("{" + Environment.NewLine);
sb.Append("return true;" + Environment.NewLine);
sb.Append("}" + Environment.NewLine);
sb.Append("else" + Environment.NewLine);
sb.Append("{" + Environment.NewLine);
sb.Append("return false;" + Environment.NewLine);
sb.Append("}" + Environment.NewLine);
sb.Append("}" + Environment.NewLine);
sb.Append("</script>" + Environment.NewLine);
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "validation", sb.ToString());
btnSearch.OnClientClick = "return ConfirmLoanAdd()";
}
and I have btnclick event
at what point do i add value to onclientclick so that message box in above function pops up?
In other words do click and onclientclick go together. By the time i want to call the js function, i already clicked the button.
Please advice the better way to do this.
Thanks