1

Hello i am creating new image button something like this ;

e.row.cells[0].text= string.empty; //clearing the cells
Imagebutton img1= new ImageButton();
img1.Id="imgInput";
img1.ImageUrl="~/sample.jpg";
img1.CommandArgument= varID; // fetching the ID
img1.click+= new ImageClickEventHandler(imgInput_Click);
e.row.controls.add(img1)

I have written the above code in gridview rowdatabound event which.

Now in the click event (imgButton_Click; handled in second last line) i wish to put the command argument value in session;

protected void imgInput_Click(object sender, EventArgs e)
{
  Session["idvalue"]= imgInput.CommandArgument; 
}

But the varID here is coming as null. Why so? What am i missing here?

Please guide! Thanks

1
  • excuse me for silly mistakes.. i have written program by myself & not copy-paste.. Commented Sep 28, 2011 at 19:15

1 Answer 1

1

You need to use the ImageButton.Command event.

Example:

  img1.Command += ImageButton_OnCommand;

  protected void ImageButton_Command(object sender, CommandEventArgs e) 
  {
     if (e.CommandName == "Sort" && e.CommandArgument == "Ascending")
        Label1.Text = "You clicked the Sort Ascending Button";
     else
        Label1.Text = "You clicked the Sort Descending Button";
  }
Sign up to request clarification or add additional context in comments.

Comments

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.