adding hyperlink between the label in asp.net - c#

I want to display message within the label by code behind.My code do look like as below.
lblmsg.Text = "Success: You have added " + pujaname + " to your shopping cart ";
Here "pujanme" is extracting from database which is coming correctly and secondly I want to inlcude "shopping cart" text which is hyperlink to other page but I am geting error.I will be pleased if somebody guides me.
Thankyou

You can try this. It is working for me.
lblmsg.Text = "Success: You have added " + pujaname +" to your shopping cart ";

You have to escape the double quotes in your link (by adding a backslash in front of them):
lblmsg.Text = "Success: You have added " + pujaname +
+ " to your shopping cart ";

You just have to precede the inner " of url with \.
lblmsg.Text = "Success: You have added " + pujaname + " to your shopping cart ";

If its vb then you can just write it simple like below: Html can be put inline as long as they are in between double quotes:
lblmsg.Text = "Success: You have added " + pujaname + " your shopping cart "

Related

Print a list after being converted from string to a Label

I'm creating a standard calculator with a history feature. Previous solutions will show in a label box every time the user clicks the "=" button
After converting this string:
string histo = (operand1 + " " + operation + " " + " " + operand2 + " = " + result);
To a list by using this code:
List<string> hist = histo.Split().ToList()
What I want to do next is to print it to a label box to show history. How can I do that? Thank you.
Your question is not very clear and I do not think that label is a good choice to show the history. Combobox would be a better option, if you want to allow users to select items from history.
As far as your question on how to display it in a label is concerned you can use the following code. You can replace "," with Environment.NewLine.
lbl.Text = String.Join(",", hist);

C# link write fault (html)

I write a small program in c# which is send datas to a blog platform.
post.Body = postContent + "<br><img src=\"" + linkToImage + "\" />";
This is working for me right, i got the result in my blog.:
<img src="http://*************.com/wp-content/uploads/2014/06/ss.jpg" />
But i would like put after the ss.jpg the next.: style="display:none"
If i tried make this.:
post.Body = postContent + "<br><img src=\"" + linkToImage + "\" + "style="display:none"" />";
Its not working. ( would like hide the image.)
I need, the end result like this link.:
<img src="http://************/wp-content/uploads/2014/06/ss.jpg" style="display:none"/>
Can somebody help me?
Thank you
There is no string interpolation required as style="display:none;" is being output as is - it is not dependant on any condition or variable in your code therefore this should work:
post.Body = postContent + "<br><img src=\"" + linkToImage + "\" style=\"display: none;\" />";

Alert not popping up for string ASP.Net

I'm stuck again with alertboxes!
This works like a charm:
Response.Write("<script>alert('" + "Hello"+ "');</script>");
result is a string. I need to display that. This is where my problem comes in. This doesn't popup:
Response.Write("<script>alert('" + result + "');</script>");
I am passing result across many layers. Also I have used this format in all pages. Don't want a message box. Or a modal popupwindow. I want this.
I checked online and according to the syntax, it is supposed to work! Please help!
To put any value in a Javascript string literal, you need to escape apostrophes (as they are used as the delimiter for the string) and backslashes:
Response.Write(
"<script>" +
"alert('" + result.Replace("'", "\\'").Replace("\\", "\\\\") + "');" +
"</script>"
);
Try this
Response.Write("<script type='text/javascript'>alert('"+result+"')</script>")
Try this
String message = String.format({0}{1}{2},
"<script type='text/javascript'>alert('",
result,
"')</script>");
Response.Write(message);
Response.Write("<script> alert('" + HttpUtility.HtmlEncode(result) + "'); </script>")

Replace this " " with this " " using C#

I am having an issue with this blank space " " showing up in my textbox if the table row is null. so i would like to replace this " " with this "". For example here is what i have:
StartTime.Text = row.Cells[5].Text;
so here is pseudo-code of what i am trying to achieve:
if (StartTime.Text == "" " then replace it with " ")
else show the value of StartTime.Text
I know my C# skills is so bad so please help. thanks
what about StartTime.Text = row.Cells[5].Text.Replace("&nbsp", " ")
or i haven't understood the question correctly

adding space and new line in html editor asp.net ajax

I want to insert blank characters in a string move to next line and align right in Html editor ajax control and it should be hardcoded in my below code .
My code is
Editor1.Content = "No. J/" + DropDownList3.SelectedItem + "-" + TextBox1.Text + "-" + tyear + "/" + " " + "/" + year + DateTime.Now.Day+"/"+DateTime.Now.Month+"/"+DateTime.Now.Year;
What i want is
i want 5 blank spaces after
....+ tyear + "/" + "....
Move to next/new line after
....." + "/" + year +....
Apply Align left to this entire
content
To add blank spaces to the keyword. Normal blank spaces will be ignored as whitespace by the HTML parser.

Categories