0

I am trying to pop something based on a condition... but it is not working... and I am kind of a newbie at this so I appreciate the help

if (myFileName == OldFileName)
                {
                    btnSubmit.Attributes["OnClick"] = "return confirm('This file already exists, do you want to replace it?');";
                }

This is not being call for some reason.. here is the asp code

asp:Button class="Button" ID="btnSubmit" CausesValidation="True" Text="SUBMIT" runat="server"
            OnClick="btnSubmit_Click"></asp:Button>
3
  • 1
    From the code in the question, it looks like you're trying to bind the JS function, not call it. Commented Jun 28, 2011 at 16:25
  • I am newbie.. I am not sure how to go around it Commented Jun 28, 2011 at 16:31
  • Are you familiar with jQuery? I like to keep javascript out of my code behind pages. Let me know if you would like an example in js or jQuery. Commented Jun 28, 2011 at 17:03

1 Answer 1

3

use a ScriptManager.

ScriptManager.RegisterStartupScript()
ScriptManager.RegisterClientScriptBlock()

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, If the validation is being done on the server-side then you will have to show the alert/confirm after the page posts back to the browser.
This is too advanced, I will mark it as answered although i am not going to use.. too involved...do not understand it. Thank you though

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.