1

In my ASP.NET web app, I have a linkbutton. If the user clicks it I wanted to use javascript to prompt the user to type in a certain value. If they type it in exactly then I will call the click event on the ASP.NET linkbutton.

The javascript would display a message like this: "Type DELETE in the textbox below to delete all data." If they type in DELETE (exactly) then I would run the click event of the asp:button. A small snippet to give you an idea of the logic....

var resp = prompt("Enter DELETE (all caps) to delete", "");

if (resp == null || resp == "") {
  alert( "Cancelled.");
} else {
  if (resp == 'DELETE') {
    alert("Run the link button code");
  } else {
    alert("Cancelled.");
  }
}

Any ideas how I can do this?

I know how to do a standard confirm. In the linkbutton I do something like this....

OnClientClick="return confirm('Are you sure you want to do this?');"

I basically want to do the same thing but with a prompt.

0

1 Answer 1

1

You can simply trigger the button click after the correct response. Just make sure you use ClientID in the script or ClientIDMode=static on the button.

if (resp == 'DELETE') {
    $('#Button1').click();

Or place a dummy LinkBUtton on the page

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" ClientIDMode="Static"></asp:LinkButton>

And use that href code

if (resp == 'DELETE') {
    WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("<%= LinkButton1.UniqueID %>", "", true, "", "", false, true));
Sign up to request clarification or add additional context in comments.

1 Comment

I wanted to run the js code in the OnClientClick of my linkbutton, as in my example. And, if they type in DELETE exactly, then run the server side click code. Make sense?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.