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;\" />";
Related
I know I must be being stupid here, but I can't work out why this code isn't working. I'm very new to Razor, so please go easy on me.
I have the following code in my markup: (I've cut it down to be as simple as I can make it while still reproducing the issue so that I can hopefully diagnose the issue easier)
string testVar = "test";
#testVar
It returns the following:
error CS0103: The name 'testVar' does not exist in the current context
I've tried using different names for the variable, I've tried having it use "var" instead of "string" for it's declaration, I've tried assigning various different values to it, I've tried surrounding the variable in brackets like #(testVar), but the issue is still there. It's very frustrating, because in another part of my code I have
string prop = #p.Name + " (" + #p.PropertyType + ") - " + #p.GetValue(#page, null).ToString() + "\r\n";
#prop
which works fine.
I can't think what could be causing it, and it's starting to frustrate me.
Thanks,
YM
In Razor when we want to write c# statements we have to tell it that from here c# code starts:
#{ // from here c# block starts
string testVar = "test";
} // here ends
Now if you want to access this variable in html you can do like this:
<span>#testVar</span>
When you are writing:
string prop = #p.Name + " (" + #p.PropertyType + ") - " + #p.GetValue(#page, null).ToString() + "\r\n";
it is considered as plain text and will be rendered on browser like "string prop = ..."
you have to tell that it is c# code by following way:
#{
string prop = #p.Name + " (" + #p.PropertyType + ") - " + #p.GetValue(#page, null).ToString() + "\r\n";
}
I have a C# application that formats a list into a HTML table which is then sent as an e-mail through Outlook.
The issue I have is rather simple but I cannot resolve. I just want to change the font size of the whole table. No matter what I do the font size does not change. My code is below and I'm aware its not pretty!
string htmlHeader = "<table><font-size=3;><tr><th align='left'>Sedol</th><th> </th><th align='left'>Name</th><th> </th><th text-align:left>Ex Date</th><th> </th><th align='left'>Dividend Type</th><th> </th><th align='left'>Dividend Contribution</th><th> </th><th align='left'>Dividend Value</th><th> </th><th align='left'>Currency</th><th> </th><th align='left'>Country of Incorp</th><th> </th></tr>";
string msgBody = htmlHeader;
for (int i = 0; i < bbergList.Count; i++)
{
string caText = "<tr><td>" + bbergList[i].Sedol + "</td><td> </td><td>"
+ bbergList[i].Name + "</td><td> </td><td>"
+ bbergList[i].dtEx.ToString("dd-MMM-yy") + "</td><td> </td><td>"
+ bbergList[i].DividendType + "</td><td> </td><td>"
+ bbergList[i].DividendValue.ToString("#,0.####") + "</td><td> </td><td>"
+ bbergList[i].DividendAmount.ToString("#,0.####") + "</td><td> </td><td>"
+ bbergList[i].DivCurrency + "</td><td> </td>"
+ bbergList[i].CountryInCorp + "</td><td> </td></tr>";
}
StringBuilder sbFinish = new StringBuilder();
msgBody = sbFinish.Append(msgBody).Append("</font></table>").ToString();
You can use something like this:
<table style="font-size:14px">
you can set the font size to whatever you want.
For a row:
<tr style="font-size:14px">
For a column:
<td style="font-size:14px">
Don't know whether you tried to format your text with C#, but as you want to publish it as html code, I would suggest to use html tags to format:
You can find different examples for formatting text like subscript etc. here:
http://www.w3schools.com/html/html_formatting.asp
And if you want to change color, this example could help:
http://www.w3schools.com/tags/att_font_color.asp
from obove site:
<font color="color_name|hex_number|rgb_number">
Use <font color="red">This is some text!</font> to get red colored font.
Best regards,
Marcus
I am trying to write a C# class that will return various code pieces to a view in MVC4. The code I am returning has both html and jquery in it. Currently I am doing the following:
output += "<table id =\"" + grid.name + "\"></table>\n";
output += "<div id=\"" + grid.pager + "\"></div>\n";
output += "jQuery(\"" + grid.name + "\") //and so on
This is my method. Output is a string. This string contains both html and jquery. I am simply returning output:
return output;
Then, in my view I am using #Html.Raw to convert the string:
#Html.Raw(MyMethod.GetString())
The problem is that the html elements a formatted correctly but the jquery elements are written to the page as plain text. Any ideas how I can get the page to turn the string into actual syntax? Should I return my string differently?
As Jquery is javascript, you should wrap this code in a <script> tag:
output += "<table id =\"" + grid.name + "\"></table>\n";
output += "<div id=\"" + grid.pager + "\"></div>\n";
output += "<script type=\"text/javascript\">jQuery(\"" + grid.name + "\");</script> //and so on
I am doing Confirmation mail sent to the register following with this URL
http://blogs.microsoft.co.il/blogs/shair/archive/2011/12/06/email-confirmation-asp-net-mvc-web-application.aspx#comments
but i am getting errors.Can anyone help me.
message.Subject = "Please Verify your Account";
MailBody.Append("<html><table cellpadding='0' cellspacing='0' width='100%' align='center'>" + "<tr><td><p>Dear " + user.UserName+ "</p><br>");
MailBody.Append("To verify your account, please click the following link:<span style='font-weight:bold;'> " + verifyUrl + "+"</span> to complete your registration.<br>);
You are missing quotes in your second append. The script highlighter even shows the error.
If you want double quotes within a string it needs to be escaped, e.g. \"
So your second appending should be something like this
MailBody.Append("To verify your account, please click the following link:<span style='font-weight:bold;'><a href=\""
+ verifyUrl + "\" target=\"http://localhost:51819\">"
+ verifyUrl + "</a></span> to complete your registration.<br>");
Your New line in constant is due to the fact you're breaking the line without telling the compiler that you want a second line.
There is 3 ways you can fix this:
don't break the line
escape every special character
use # sign to do what you want
As an example:
StringBuilder sb = new StringBuilder();
sb.Append("<html><table cellpadding='0' cellspacing='0' width='100%' align='center'>");
sb.Append("<tr><td><p>Dear " + user.UserName+ "</p><br>");
sb.Append("To verify your account, please click the following link:<span style='font-weight:bold;'>");
sb.Append("<a href='" + verifyUrl + "' target='http://localhost:51819'>" + verifyUrl + "</a></span> to complete your registration.<br>");
MailBody.Append(sb.ToString());
You also need to avoid using a mix of single and double quotes inside a string, the idea is to only use single quotes inside and use double quotes to delimit the string.
You can also use the # in front of a string and you can then break the line like this:
MailBody.Append(
String.Format(
#"<html>
<table cellpadding='0' cellspacing='0' width='100%' align='center'>
<tr>
<td>
<p>Dear {0}</p>
To verify your account, please click the following link:
<span style='font-weight:bold;'>
<a href='{1}'>{1}</a>
</span> to complete your registration.
</td>
</tr>
</table>
</html>", user.UserName, verifyUrl));
I also used StringBuilder to avoid having variables inside the template, as it makes it way more simple to see and edit.
And last, but not least, you should know a little bit more about HTML ... there is no such thing as target="http://localhost:51819"...
Your second MailBody.Append is all messed up
MailBody.Append("To verify your account, please click the following link:<span style='font-weight:bold;'> " + verifyUrl + "</span> to complete your registration.<br>");
i have written the below code now i want to check whether the below code is write
bcoz when i run the program it gives me a error help needed am i doing something wrong in below code if yes plz rectify me
i m not sure how to pass query string throrugh javascript
Page.ClientScript.RegisterClientScriptBlock
(this.GetType(), "OnClick", "<script language=javascript>window.opener.location.href='~/Home.aspx?Flag= + iFlag + &BetaFlag= + iFlagBeta + &iManuf= + iManuf';</script>"
);
thanks in advance
The problem it seems to be in string creation.
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OnClick", "<script language=javascript>window.opener.location.href='~/Home.aspx?Flag=" + iFlag + "&BetaFlag=" + iFlagBeta + "&iManuf=" + iManuf + "';</script>");
Try this:
Page.ClientScript.RegisterClientScriptBlock
(this.GetType(), "OnClick",
#"<script language=javascript>
window.opener.location.href='~/Home.aspx?Flag=" + iFlag + "&BetaFlag=" + iFlagBeta + "&iManuf=" + iManuf + "';</script>"
);