LinkButton Problem

S

Sam Solomon

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:[email protected]>[email protected]</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.
 
B

Ben

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;

}

}
 
S

Sam Solomon

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:[email protected]>[email protected]</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
 
P

Phillip Williams

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:[email protected]";
hl.Text="(e-mail address removed)";
phError.Controls.Add(hl);
lbl = new Label ();
lbl.Text =" or ring 22222";
phError.Controls.Add(lbl);
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,088
Latest member
JeremyMedl

Latest Threads

Top