LinkButton Problem

Discussion in 'ASP .Net Web Controls' started by Sam Solomon, Oct 26, 2005.

  1. Sam Solomon

    Sam Solomon Guest

    Dear All,

    I want to know that how can I display a link button in a string and use its
    events. Below is my string:



    lblError.Text="Unfortunately your details were not found in the
    database.Please try again contact <a
    href=mailto:></a> or ring 22222";


    In the above string i want "try again" to be a hyperlink. And also i want to
    make use of its click event.

    Any help would be greatly appreciated.

    Thanking you in anticipation,

    cheers,

    Sam Solomon.
    Sam Solomon, Oct 26, 2005
    #1
    1. Advertising

  2. Sam Solomon

    Ben Guest

    Add this to you aspx page

    Please <asp:LinkButton ID="lbtry" Runat="server"
    OnCommand="btn_Command" CommandName="try">try again</asp:LinkButton>
    contact

    in code behind..add the following
    protected void btn_Command(object sender, CommandEventArgs e)
    {
    switch(e.CommandName)
    {
    case "try":
    //your logic here break;

    }

    }


    *** Sent via Developersdex http://www.developersdex.com ***
    Ben, Oct 26, 2005
    #2
    1. Advertising

  3. Sam Solomon

    Sam Solomon Guest

    Dear Ben,

    Thanks for your kind reply. I tried your code but still I cann't see the
    Link Button. Below is my code again:

    lblError.Text="Unfortunately your details were not found in the
    database.Please<asp:LinkButton id=\"lnkTryAgain\" Runat=\"Server\">Try
    again</asp:LinkButton> or contact <a
    href=mailto:></a> or ring 22222";

    I am using C# so placed \ so that that it can show "" around lnkTryAgain and
    Server.

    Any help would be greatly appreciated.

    cheers,
    Sam Solomon



    "Ben" wrote:

    > Add this to you aspx page
    >
    > Please <asp:LinkButton ID="lbtry" Runat="server"
    > OnCommand="btn_Command" CommandName="try">try again</asp:LinkButton>
    > contact
    >
    > in code behind..add the following
    > protected void btn_Command(object sender, CommandEventArgs e)
    > {
    > switch(e.CommandName)
    > {
    > case "try":
    > //your logic here break;
    >
    > }
    >
    > }
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    >
    Sam Solomon, Oct 27, 2005
    #3
  4. Hi Sam,

    A Hyperlink can either process a postback to the server or navigate to an
    emailer/url reference but not both.

    In the scenario you presented you should do any server processing you want
    to do (e.g. saving the user's info) before you composed the lblError message.

    To add server controls to the error message you need to use a different
    control other than the Label control. Try the placeholder as follows:
    1) in the webform:
    <asp:placeHolder ID="phError" Runat="server"></asp:placeHolder>

    2) in the codebehind:
    //---- add a label ----
    Label lbl = new Label();
    lbl.Text= "Unfortunately your details were not found in the database.Please
    try again contact ";
    phError.Controls.Add (lbl);
    HyperLink hl = new HyperLink ();
    hl.NavigateUrl = "mailto:";
    hl.Text="";
    phError.Controls.Add(hl);
    lbl = new Label ();
    lbl.Text =" or ring 22222";
    phError.Controls.Add(lbl);

    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Sam Solomon" wrote:

    > Dear All,
    >
    > I want to know that how can I display a link button in a string and use its
    > events. Below is my string:
    >
    >
    >
    > lblError.Text="Unfortunately your details were not found in the
    > database.Please try again contact <a
    > href=mailto:></a> or ring 22222";
    >
    >
    > In the above string i want "try again" to be a hyperlink. And also i want to
    > make use of its click event.
    >
    > Any help would be greatly appreciated.
    >
    > Thanking you in anticipation,
    >
    > cheers,
    >
    > Sam Solomon.
    >
    Phillip Williams, Oct 27, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike

    LinkButton Problem

    Mike, Feb 27, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    656
  2. Rob Meade

    LinkButton / doPostBack problem

    Rob Meade, Aug 25, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    4,040
    Raterus
    Aug 25, 2004
  3. Henri
    Replies:
    2
    Views:
    732
    Henri
    Oct 5, 2004
  4. Sathyaish
    Replies:
    3
    Views:
    3,096
    Sathyaish
    Sep 8, 2005
  5. Sathyaish

    Linkbutton does not look like a linkbutton

    Sathyaish, Sep 8, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    179
    Sathyaish
    Sep 8, 2005
Loading...

Share This Page