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
Related
I have the following HTML code:
var textBody1 = "My URL";
var url = "http://www.google.co.il";
var html = "<table width = '100%'><tr><td align='left' style=font-family:'Arial'>"
+ "<a href='http://www.google.co.il' target='blank'>" + textBody1 + "</a>"
+ "</td></tr></table>";
The var textBody1 is concatenated to the html tags, so that the final html page will show its value.
My challenge is to implement the same thing,
this time for the url variable.
Unfortunately I couldn't find the right way to bind the parameter into a middle of a tag. Can anyone help me please?
Tali.
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;\" />";
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>")
I need to create a pdf from .aspx page. In .aspx page user will enter so many values in textbox and gridview. It also has some tabs with different sections. I did used iTextSharp for creating simple pdf. But here i need to get the values from the page and need to read the tab controls. So is it posible to use iTextSharp or is there any opensource dll available for converting .aspx to pdf..
Give me some idea?
Thanks..
By using ITextsharp library,this can be done by using HTMLWorker :
First Create String builder;
private StringBuilder sb;
Then add pdf heading from textbox value as:
sb.Append("<p style=\"text-align: center;font-size:" + fontSize + "px;font-weight:" + (bold ? "bold" : "normal") + ";\">" + txtHeading + "</p>");
Then add subject to pdf from textbox value as:
sb.Append("<table><tr valign=\"top\"><td>Subj:</td><td style=\"font-size:" + fontSize + "px;font-weight:bold;text-decoration:underline;\">" + txtSubject.text + "</td></tr></table><br />");
Then add paragraphs from textbox value as:
sb.Append("<p style=\"text-align: left;font-size:" + fontSize + "px;font-weight:" + (bold ? "bold" : "normal") + ";\">" + txtParagraph + "</p><br/>");
for table creation take values in string[] array
sb.Append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"0.5\"><thead><tr align=\"center\" valign=\"top\">");
foreach (string str in StringArray)
{
sb.Append("<th><strong>" + str + "</strong></th>");
}
sb.Append("</tr></thead>");
And so on.You can create pdf from textbox values of aspx page.
Itext Sharp quite easy .about tabs ,I dont know may be it will work ,as it works for paging ,I mean it converts all the matter in the paging ,in a single pdf
Click Here For Example
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.