Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4236366
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:37:44+00:00 2026-05-21T02:37:44+00:00

Hey guys Im getting no postback on my button? I have it tied to

  • 0

Hey guys Im getting no postback on my button? I have it tied to Javascript like so:

<script type="text/javascript">
function confirm_delete()
{
  if (confirm("Are you sure you want to delete this comment?")==true)
    return true;
  else
    return false;
}
</script>
<p>
<asp:Button ID="btn" OnClientClick="if(confirm_delete()){/* post back*/}else{return false;};" OnClick="btnDelete_Click" runat="server" CssClass="Btn" Text="delete"/>

But when I click ok on confirm no postback is initiated, its initiated if I click the button manually?

private void PopulateWallPosts(string userId)
{

    using (OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=root; Password=commando;"))
    {
        cn.Open();
        using (OdbcCommand cmd = new OdbcCommand("SELECT idWallPosting, wp.WallPostings, p.PicturePath FROM WallPosting wp LEFT JOIN User u ON u.UserID = wp.UserID LEFT JOIN Pictures p ON p.UserID = u.UserID WHERE wp.UserID=" + userId + " ORDER BY idWallPosting DESC", cn))
        {
            //("SELECT wp.WallPostings, p.PicturePath FROM WallPosting wp LEFT JOIN [User] u ON u.UserID = wp.UserID LEFT JOIN Pictures p ON p.UserID = u.UserID WHERE UserID=" + userId + " ORDER BY idWallPosting DESC", cn))
            using (OdbcDataReader reader = cmd.ExecuteReader())
            {
                test1.Controls.Clear();

                while (reader.Read())
                {

                    System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                    div.Attributes["class"] = "test";


                    div.ID = String.Format("{0}", reader.GetString(0));
                    // this line is responsible, problem here and my sqlsntax, im trying to set the SELECT idWallPosting for the div ID
                    Image img = new Image();
                    img.ImageUrl = String.Format("{0}", reader.GetString(2));

                    img.AlternateText = "Test image";

                    div.Controls.Add(img);
                    div.Controls.Add(ParseControl(String.Format("&nbsp&nbsp&nbsp;" + "{0}", reader.GetString(1))));
                    div.Attributes.Add("onclick", "return confirm_delete();");

                    div.Style["clear"] = "both";
                    test1.Controls.Add(div);

                }
            }
        }
    }
}

protected void btnDelete_Click(object sender, EventArgs e)
{

    string id = "ctl00_ContentPlaceHolder1_ContentPlaceHolder2_26";
    string[] idFragments = id.Split('_');
    id = idFragments[idFragments.Length - 1];

    //serverside code if confirm was pressed.
        using (OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=root; Password=commando;"))
        {
            cn.Open();
            using (OdbcCommand cmd = new OdbcCommand("DELETE FROM WallPosting WHERE idWallPosting = " + id + ")", cn))
            {
                cmd.ExecuteNonQuery();
            }
        }
        //PopulateWallPosts();

}

EDIT: Tried this:

function confirm_delete()
{
  if (confirm("Are you sure you want to delete this comment?") == true)
    return true;
  else
    return false;
}
</script>
<p>
<asp:Button ID="btn" OnClientClick="return confirm_delete();" OnClick="btnDelete_Click" runat="server" CssClass="Btn" Text="delete"/>

still no postback

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:37:44+00:00Added an answer on May 21, 2026 at 2:37 am

    I don’t see anywhere that you’re explicitly telling asp.net that your confirmation was successful. Remember if you don’t return something, then it will default to false. Your OnClientClick should just be "return confirm_delete();", then it should work.

    OnClientClick is always suppposed to return a boolean letting ASP.NET know that it should indeed post back and fire your server-side OnClick event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I have a little button functionality that is not erring, but also
Hey Guys, Anyone have any idea why I'm getting the warning pictured in the
hey guys, i'm getting an exception on the following inner exception: {Value cannot be
Hey guys! I keep getting a syntax error (unexpected $end), and I've isolated it
Hey guys. This is a follow-on from this question : After getting the right
Hey guys, working on an event calendar. I'm having some trouble getting my column
Hey guys, I have been programming with as3 for the past 4 months and
Hey guys, I have a client who wants their front site to have a
Hey guys, I have a question about Sphinx. I use Sphinx to index the
Hey guys! I'm getting a problem that is driving me crazy. I defined an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.