Usercontrol + linkbutton

Last post 09-12-2008 12:40 PM by bmains. 4 replies.

Sort Posts:

  • Usercontrol + linkbutton

    09-12-2008, 8:51 AM
    • Member
      7 point Member
    • marco440
    • Member since 05-05-2005, 1:59 PM
    • Posts 10

    I need to get a CommandArgument from linkbutton inside a userControl

    for this pourpose I'm using this code

    public partial class userControl_menu : System.Web.UI.UserControl
    {
    //private string _argument;
    public string argument
    {
    get
    {
    return ViewState["argument"] == null ?
    "Default Value!" :
    (string)ViewState["argument"];
    }
    set { ViewState["argument"] = value; }
    }
    protected void Page_Init(object sender, EventArgs e)
    {
    nuovi.Command += new CommandEventHandler(imgClick);
    anagrafiche.Command += new CommandEventHandler(imgClick);
    catalogo.Command += new CommandEventHandler(imgClick);
    }
    protected void imgClick(object sender, CommandEventArgs e)
    {
    argument = e.CommandArgument.ToString();
    }
    }

    but when i'm trying to get the value in the destination page i get "Default Value!"

    if i  re-click  I get the correct value

    now, does anyone know what is the correct way to do what I need in the first click?

    thank you bye 

    Marco

  • Re: Usercontrol + linkbutton

    09-12-2008, 11:09 AM
    • All-Star
      27,952 point All-Star
    • bmains
    • Member since 10-22-2004, 8:20 AM
    • Posts 5,636
    • TrustedFriends-MVPs

    Hey,

    Are you trying to access it on the same postback as the  button click?  Are you checking it in page load?  Button click handlers fire after page load, and the proper place to process it is in the prerender event.

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: Usercontrol + linkbutton

    09-12-2008, 11:21 AM
    • Member
      7 point Member
    • marco440
    • Member since 05-05-2005, 1:59 PM
    • Posts 10

    yes this is exactly what I do but nothing happen

    when I set a point of debbuger over    " protected void imgClick(object sender, CommandEventArgs e)"  this is not fired (the first click)

    looks like the PostBackUrl come before but I don't know

  • Re: Usercontrol + linkbutton

    09-12-2008, 11:31 AM
    • Participant
      1,331 point Participant
    • AjPtl
    • Member since 01-25-2007, 3:21 PM
    • DE, USA
    • Posts 270

     There are two ways : 1st in aspx page use prerender event as per bmains 

    or 2nd you have to create delegate/event for your user control

    Anuj Patel
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If this post answers your question please mark it as Answered.
  • Re: Usercontrol + linkbutton

    09-12-2008, 12:40 PM
    Answer
    • All-Star
      27,952 point All-Star
    • bmains
    • Member since 10-22-2004, 8:20 AM
    • Posts 5,636
    • TrustedFriends-MVPs

    Hey,

    You could use the Click event instead; also Command is only fired if CommandName is established.

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
Page 1 of 1 (5 items)