Reply to topic
How to do a PostBack from a Text Link
whitesites


Joined: 05 Jul 2004
Posts: 173
Location: Houston, TX
Reply with quote
Even though I have it working its not working the way I want.

The idea is to have some text directly call one of my ServerSided ASP.NET functions.

Basically I am trying to delete photos

This is the code in my Page_Load function

Code:
//delete photo
   if(Page.IsPostBack){
      if(Request.Form["__EVENTARGUMENT"]!=""){
         deletephoto(Request.Form["__EVENTARGUMENT"]);
      }
   }


This is the code in my function that deletes the photo

Code:
void deletephoto(string id){
   // get photo
   Response.Write("function called for "+id);
   string photo=countDB3("SELECT filename FROM blogs_photos WHERE id='"+id+"'");
   if(photo!=""){
      //delete photo
      string filepath="blogs/large/"+photo;
      File.Delete(Server.MapPath(filepath));
      
      filepath="blogs/medium/"+photo;
      File.Delete(Server.MapPath(filepath));
      
      filepath="blogs/small/"+photo;
      File.Delete(Server.MapPath(filepath));
      
      filepath="blogs/thumb/"+photo;
      File.Delete(Server.MapPath(filepath));
   }
   insertToDB("DELETE FROM blogs_photos WHERE id='"+id+"'");
   }


Here is a javascript function from the client side
Code:
function deletepic(picid)
{
   __doPostBack('deletephoto',picid);
}


and here is the text link
Code:
<a href="javascript:deletepic('id_of_photo');">DELETE</a>


What I want to do is directly call my deletephoto ASP.NET function without the check in my Page_Load to see if its a PostBack. Is there anyway to do this?
bobum
Elvis Fanatic
Elvis Fanatic

Joined: 16 Nov 2004
Posts: 746
Location: Montgomery, AL
Reply with quote
Pretty sure it'll always fire the page load - i usually check for a negative though like below...

Code:
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" CommandName='123'>LinkButton</asp:LinkButton>


Code:
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //I won't fire when the linkbutton is clicked
            int i = 1;
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        deletephoto(LinkButton1.CommandName);
    }


Any help?

You doing this in a grid or just somewhere on the page?
How to do a PostBack from a Text Link
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic