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 4115746
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:37:18+00:00 2026-05-20T22:37:18+00:00

Can any one help me with this code: ASP: <script type=text/javascript> function confirm_delete(div.ID)// problem

  • 0

Can any one help me with this code:

ASP:

    <script type="text/javascript">
        function confirm_delete(div.ID)// problem here{
            if (confirm('Are you sure you want to delete?')) {
                __doPostBack('DivClicked', div.ID);
// not sure if javascript will pick up on the string from server side code
            }
            else {
                return false;
            }
        }

Page Load code behind:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            //It is a postback so check if it was by div click
            string target = Request["__EVENTTARGET"];
            if (target == "DivClicked")
            {
                String.Format(div.ID) = Request["__EVENTARGUMENT"];
                // problem converting div.ID from Javascript to string (because of the dot)

                Response.Write(String.Format(div.ID));
               // same problem here
            }
        }
        string theUserId = Session["UserID"].ToString();
        PopulateWallPosts(theUserId);
    }

Code Behind:

               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));
                    Convert.ToString(div.ID);
                    //store the div id as a string
                    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.ID + ");");
                    // send the div id to javascript, not sure this line will work
                    div.Style["clear"] = "both";
                    test1.Controls.Add(div);

                }
            }
        }
    }
}
  • 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-20T22:37:19+00:00Added an answer on May 20, 2026 at 10:37 pm

    There are quite a few problems with your code. First, the argument to a javascript function must be a legal variable name. You are using a property reference on a variable. Second, I suspect that you may be using numeric ids for your DIV ids. Note that they have to start with a letter and must be unique. It’s possible yours are this way, but given that they seem to refer to comment ids it seems likely that they may be fully numeric. Third, you probably should be passing back the id of the control in the __EVENTTARGET parameter, that’s what the frame work expects. Fourth, just return false if it isn’t confirm. That will cancel the normal action. If it is confirmed, you’re doing the postback manually and still want the normal action cancelled. Note that it is a full postback, not AJAX so you should return a full page. Fifth, you need to put quotes around the id when you write out the javascript. Lastly, there are much better ways to do this, but it would take more than just one answer to show you how. Look for information on using AJAX with web forms.

    ASPX

    function confirm_delete(id) {
        if (confirm('Are you sure you want to delete?')) {
            __doPostBack(id,'');
        }
        return false;
      }
    

    Page Load

       if (Page.IsPostBack)
        {
            string target = Request["__EVENTTARGET"];
            if (target.StartsWith("comment"))
            {
                // remove comment string to get actual id
                string id = target.Replace( "comment", "" );
    
                // now do something with the id, like delete the comment?
            }
        }
        // finish the page
        string theUserId = Session["UserID"].ToString();
        PopulateWallPosts(theUserId);
    

    Code-behind

     while (reader.Read())
     {
    
        var div = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
        div.Attributes["class"] = "test";
    
    
        div.ID = String.Format("comment{0}", reader.GetString(0));
    
        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))));
        // the single quotes in the line below are critical
        div.Attributes.Add("onclick", "return clickTheButton('" + div.ID + "');");
        div.Style["clear"] = "both";
        test1.Controls.Add(div);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can Any one help me reading this XML and Looping through <MedicationDispensed> I get
Can any one please help me solve this. I am resizing some flash object/embed
Can any one help me, i already checked resizing demo but this work through
I am calling the following JS to validate a UK postal code: <script type=text/javascript>
Can anyone help me figure out whats wrong with this piece of xaml code?
Can anyone help in this php page navigation script switch on counting normal serial
Can anyone help me with this error? alt text http://abbeylegal.com/downloads/parsererror.jpg full image here It
Can anyone help - this is driving me mad. I am calling a mysql
Can anyone help with this... vector<unsigned int> *vVec = new vector<unsigned int>; vVec .reserve(frankReservedSpace);
Can anyone help convert this this actionscript to Objective-c? if(mcMain.y >= stage.stageHeight - mcMain.height)

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.