When I created a method in a controller I would like the output which is HTML to be displayed in the view. Although I see the functions results as the expected html it does not display in the page.
I've tried the HtmlHelper Html.Raw
<table class="table table-bordered table-framed" id="seconDTable" style="display:block;height:100%;">
<tbody>
#if (caseFile.Length > 0 && RenamedCaseFileName.Length > 0)
{
<tr>
<td style="width: 100%;">
<input type="checkbox" id="CheckBox" title="Select All Bookmarks" onchange="changeCheckBox();" class="styled" />
<span>Select All</span>
</td>
</tr>
if (oGdPicturePDFstatus == GdPicture14.GdPictureStatus.OK)
{
int rootID = oGdPicturePDF.GetBookMarkRootID();
oGdPicturePDFstatus = oGdPicturePDF.GetStat();
if (oGdPicturePDFstatus == GdPicture14.GdPictureStatus.OK)
{
IHtmlString str = new HtmlString(GetPDFBookmarks.ParseBookmarksOutlines(oGdPicturePDF, rootID, 0));
Html.Raw(str);
}
else
{
if (oGdPicturePDFstatus == GdPicture14.GdPictureStatus.PropertyNotFound)
{
<tr>
<td style="width: 100%;">
This PDF document doesn't contain any bookmarks.
</td>
</tr>
}
}
}
oGdPicturePDF.Dispose();
}
</tbody>
</table>
Function:
public string ParseBookmarksOutlines(GdPicturePDF oGdPicturePDF, int bookmarkID, int level)
{
string title = "";
GdPictureStatus status = GdPictureStatus.OK;
string cssType = string.Empty;
string TableRows = string.Empty;
while (true)
{
title = oGdPicturePDF.GetBookMarkTitle(bookmarkID);
status = oGdPicturePDF.GetStat();
if (level == 0)
{
cssType = "ParentsourcefileCheckBox";
}
else
{
cssType = "ChildsourcefileCheckBox";
}
if (status == GdPictureStatus.OK)
{
TableRows = TableRows + "<tr><td style=\"width: 100 %; \">";
TableRows = TableRows + "<input name=\"sourcefileCheckBox\" type=\"checkbox\" class=\"" + cssType + "\" id=\"checkBox\" value=\"" + bookmarkID + "\" />";
TableRows = TableRows + "<span>" + title + "</span>";
TableRows = TableRows + "</td></tr>";
}
else
{
TableRows = TableRows + "<tr><td>";
TableRows = TableRows + "Title: this error occurs - " + status.ToString() + " Level: " + level.ToString() + "\n";
TableRows = TableRows + "</td></tr>";
//message = message + "Title: this error occurs - " + status.ToString() + " Level: " + level.ToString() + "\n";
}
if (bookmarkID == 0)
{
break;
}
}
return TableRows;
}
I'm expecting the checkboxes to be displayed on the final rendered page instead it does not display ay all.
enter image description here
The answer was the following:
#Html.Raw(HttpUtility.HtmlDecode(GetPDFBookmarks.ParseBookmarksOutlines(oGdPicturePDF, rootID, 0)));
It was located in the post:
Return html string from controller and display in view
I am using a xaml wpf grid. I want to convert struct the grid to json. Do you have any ideas on how?
Please see this example:
<GridBinding>
<Grid ID="grd1" ES="9" KFN="" PFN="" GN="گرید 1">
<Column ID="ID" SystemId="517" TableId="3082" FieldId="1" Properties="Header=ID,Visible=True,VisibleIndex=4,GroupIndex=-1,ReadOnly=True,SortIndex=1,SortOrder=Descending,Mask=0,Width=ناعدد," IsCondition="False" IsForce="False" VS="True" ISFormulla="False" VF="1" ReadOnly="True" />
<Column ID="Name" SystemId="517" TableId="3082" FieldId="2" Properties="Header=Name,Visible=True,VisibleIndex=1,GroupIndex=-1,ReadOnly=False,SortIndex=2,SortOrder=Ascending,Mask=0,Width=ناعدد," IsCondition="False" IsForce="False" VS="True" ISFormulla="False" VF="2" ReadOnly="False" />
<Column ID="Family" SystemId="517" TableId="3082" FieldId="3" Properties="Header=Family,Visible=True,VisibleIndex=2,GroupIndex=-1,ReadOnly=False,SortIndex=-1,SortOrder=None,Mask=1,Width=ناعدد," IsCondition="False" IsForce="False" VS="True" ISFormulla="False" VF="3" ReadOnly="False" />
<Column ID="Avg" SystemId="517" TableId="3082" FieldId="10" Properties="Header=Avg,Visible=True,VisibleIndex=3,GroupIndex=-1,ReadOnly=False,SortIndex=-1,SortOrder=None,Mask=0,Width=ناعدد," IsCondition="False" IsForce="False" VS="True" ISFormulla="False" VF="4" ReadOnly="False" />
<Column ID="ردیف" SystemId="0" TableId="0" FieldId="-1" Properties="Header=ردیف,Visible=True,VisibleIndex=0,GroupIndex=-1,ReadOnly=False,SortIndex=-1,SortOrder=None,Mask=0,Fixed=Left,Width=ناعدد," IsCondition="False" IsForce="False" VS="False" ISFormulla="False" VF="0" ReadOnly="False" />
</Grid>
</GridBinding>
I want this result:
var object = {
"grd1": [ {
ID: "ID",
Visible: "True",
FieldId: "1",
IsForce: "false",
ReadOnly="true"
} ],
};
This is my code:
if ((item as XmlElement).Attributes["Type"].Value == "Grid") {
if (Id_elem == (itemgrigIn as XmlElement).Attributes["ID"].Value) {
if (Orientation == "Horizontal" || Orientation == "" || Orientation == null) {
s += " <div id=" + Id_elem + "myDiv" +
" dir='rtl' align='center' class='table-responsive'></div> " +
" <script> $(document).ready(function() {var " +
Id_elem + "Divresult = $(" + "'" + "<div id=" +
Id_elem + "Div" + " ></div>);" +
"'" + " $(" + Id_elem + "Div" + ").append(" +
Id_elem + "Divresult); var " +
Id_elem + " = new grid(" + "'" + Id_elem + "'" +
"," + countgrid + ");" + Id_elem +
".init(); }); </script> ";
}
}
}
It is not trivial task. If you want make all right You must first create a parser from xaml string to object. And then parser from object to json string. You must research and find libs to convert xml and json.
hi iam sloved this problem
1- first use XmlNode
public string CreateHtml(Form formInfo, XmlNode _MainNode,string oldHtml)
{
ConvertXmlToHtml(_MainNode, ref Result);
}
public void ConvertXmlToHtml(XmlNode XmlElement, ref string s)
{
PropertyInfo _propList = new PropertyInfo();
#region grid for create arrye
foreach (XmlNode item in XmlElement.ChildNodes)
{
if (item.Name == "AvailableItems" || item.Name == "DataSource" || item.Name == "GridBinding")
{
continue;
}
if ((item as XmlElement).Attributes["Type"].Value == "Grid")
{
string Id_elem = (item as XmlElement).Attributes["ID"].Value;
foreach (XmlNode itemgrigOut in XmlElement.ChildNodes)
{
if (itemgrigOut.Name == "GridBinding")
{
countgrid++;
if (countgrid < 2)
s += "<script> $(document).ready(function() { var object_grid = {" ;
foreach (XmlNode itemgrigIn in itemgrigOut)
{
if (Id_elem == (itemgrigIn as XmlElement).Attributes["ID"].Value)
{
s += Id_elem + " :[ ";
if (Orientation == "Horizontal" || Orientation == "" || Orientation == null)
{
//ساخت گرید مورد نظر
}
else
{
foreach (XmlNode itemcildgrid in itemgrigIn)
{
if ((itemcildgrid as XmlElement).Attributes[Properties.Resources.PropertiesInfo] != null)
_propList = new PropertyInfo() { PropertyList = (itemcildgrid as XmlElement).Attributes[Properties.Resources.PropertiesInfo].Value };
s += " { ID : " + ReturnAttribute((itemcildgrid as XmlElement), "IDgrid", false);
s += ", Visible : " + ReturnAttribute((itemcildgrid as XmlElement), "Visible", false);
s += ", VisibleIndex : " + ReturnAttribute((itemcildgrid as XmlElement), "VisibleIndex", false);
s += ", ReadOnly : " + ReturnAttribute((itemcildgrid as XmlElement), "ReadOnly", false);
s += ", SortOrder : " + ReturnAttribute((itemcildgrid as XmlElement), "SortOrder", false);
s += ", Mask : " + ReturnAttribute((itemcildgrid as XmlElement), "Mask", false);
s += ", IsCondition : " + ReturnAttribute((itemcildgrid as XmlElement), "IsCondition", false);
s += ", ISFormulla : " + ReturnAttribute((itemcildgrid as XmlElement), "ISFormulla", false);
s += ", ReadOnly : " + ReturnAttribute((itemcildgrid as XmlElement), "ReadOnly", false);
s += ", IsForce : " + ReturnAttribute((itemcildgrid as XmlElement), "IsForcegrid", false);
s += "}, ";
}
s += "], ";
}
}
}
}
}
}
}
if (countgrid == CountAll_grid)
s += " } }); </script> ";
#endregion
#region grid
foreach (XmlNode item in XmlElement.ChildNodes)
{
childCount++;
if (item.Name == "AvailableItems" || item.Name == "DataSource" || item.Name == "GridBinding")
{
continue;
}
if ((item as XmlElement).Attributes["Type"].Value == "Grid")
{
string Id_elem = (item as XmlElement).Attributes["ID"].Value;
foreach (XmlNode itemgrigOut in XmlElement.ChildNodes)
{
if (itemgrigOut.Name == "GridBinding")
{
//شمارش تعداد گریدها
countgrid++;
if (countgrid ==0)
{ }
foreach (XmlNode itemgrigIn in itemgrigOut)
{
if (Id_elem == (itemgrigIn as XmlElement).Attributes["ID"].Value)
{
if (Orientation == "Horizontal" || Orientation == "" || Orientation == null)
{
//ساخت گرید مورد نظر
s += string.Format("<br/><div dir = 'rtl' align = 'center' class='table-responsive'><div class='row well'>" +
"<table id=" + Id_elem + "cellpadding='0' cellspacing='0'></table> <div id = pager_" + Id_elem + "></div></div></div>"
);
}
else
{
s += " <div id=" + Id_elem + "myDiv" + " dir='rtl' align='center' class='table-responsive'></div> " +
" <script> $(document).ready(function() {var " + Id_elem + "Divresult = $(" + "'" + "<div id=" + Id_elem + "Div" + " ></div>" + "'" + ") ; " +
" $(" + Id_elem + "Div" + ").append(" + Id_elem + "Divresult); var " + Id_elem + " = new grid(" + "'" + Id_elem + "'" + "," + countgrid + ");" + Id_elem + ".init(); }); </script> ";
$(document).ready(function() {var object_grid = {" + Id_elem +" :[ ";
}
}
}
}
}
}
#endregion
}
Why does the following code works perfectly in browsers like Chrome 41, Firefox 36 and IE 10 but doesn't work as expected in the WebBrowser control in Windows Forms?
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
html, body {
height: 100%;
margin: 0;
padding: 0;
width: 100%;
}
body {
display: table;
}
.my-block {
text-align: center;
display: table-cell;
vertical-align: middle;
}
</style>
</head>
<body>
<div class="my-block">Some text</div>
</body>
</html>
This solution is from this answer (JSFiddle).
this.webBrowser.DocumentText =
"<!DOCTYPE HTML>" +
"<html>" +
"<head>" +
"<style type=\"text/css\">" +
"html, body {" +
"height: 100%;" +
"margin: 0;" +
"padding: 0;" +
"width: 100%;" +
"}" +
"body {" +
"display: table;" +
"}" +
".my-block {" +
"text-align: center;" +
"display: table-cell;" +
"vertical-align: middle;" +
"}" +
"</style>" +
"</head>" +
"<body>" +
"<div class=\"my-block\">Some text</div>" +
"</body>" +
"</html>";
This code gives me the following result:
Why? What am I doing wrong? How can I fix it?
Thanks in advance.
I am struggling with an IE/Silverlight bug which seems to be known since quite a while: When a silverlight page is refreshed in IE10, the app turns into a white page. No error messages or anything alike. I am using IE11 and the behavior is the same. It is absolutely ridiculous that such a showstopper still hasn't been fixed and I was not able to find one helpful response from Microsoft. Anyway, I found workarounds in this thread:
SO thread
but I don't manage to get any of the workarounds to work properly.
This is my latest try:
<%# Page Language="c#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Manager</title>
<style type="text/css">
html, body {
height: 100%;
overflow: auto;
}
body {
padding: 0;
margin: 0;
}
#silverlightControlHost {
height: 100%;
text-align:center;
}
</style>
<script type="text/javascript" src="Silverlight.js"></script>
<script type="text/javascript">
function onSilverlightError(sender, args) {
var appSource = "";
if (sender != null && sender != 0) {
appSource = sender.getHost().Source;
}
var errorType = args.ErrorType;
var iErrorCode = args.ErrorCode;
if (errorType == "ImageError" || errorType == "MediaError") {
return;
}
var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n" ;
errMsg += "Code: "+ iErrorCode + " \n";
errMsg += "Category: " + errorType + " \n";
errMsg += "Message: " + args.ErrorMessage + " \n";
if (errorType == "ParserError") {
errMsg += "File: " + args.xamlFile + " \n";
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
else if (errorType == "RuntimeError") {
if (args.lineNumber != 0) {
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
errMsg += "MethodName: " + args.methodName + " \n";
}
throw new Error(errMsg);
}
</script>
<meta http-equiv="x-ua-compatible" content="IE=8" />
</head>
<body>
<form id="form1" runat="server" style="height:100%">
<a id="myLink" ></a>
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/Manager.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="5.0.61118.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=5.0.61118.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object>
<script type="text/javascript" language="javascript">
var shc = document.getElementById("silverlightControlHost");
document.getElementById("myLink").focus();
</script>
</div>
</form>
</body>
</html>
Here I included the meta-tag for compatibility mode and the java snippet to focus another control. Neither seems to work.
Are there any updates on this issue which I have missed?
Are there any mistakes in the code shown above?
Could someone post a complete page which implements a working workaround?
Additional information:
OS: Windows 8.1
IE: 11.0.96000
SL: 5.1.30514.0
I create a table for searching items on ajax auto complete, I want to design like that(Table-1):
There is my web service code:
[WebMethod]
public object[] GetResult(string prefixText, int count)
{
List<object> result;
result = new List<object>();
try
{
Some Database query...
while (rd.Read())
{
result.Add(new
{
ProductName = rd[0],
Pic= rd[1],
RecID = rd[2],
Properties= rd[3]
});
}
rd.Close();
con.Close();
}
catch (Exception ex)
{
}
return result.ToArray();
}
I add a List object for all data and its java script side:
<script type="text/javascript">
function onPopulated() {
var list = $find("ace").get_completionList();
var count = list.childNodes.length;
for (i = 0; i < count; i++) {
var item = list.childNodes[i]._value;
var name = item.ProductName ;
var kategory = item.Properties;
var RecID = item.RecID;
var Pic= item.Pic;
var url = "http://abc.com.tr/img/p_" + RecID + "_" + Pic+ "_01.jpg"
list.childNodes[i].innerHTML = '<span id="name"><table><tr style="width:260px;height:55px;" ><td><img width="50" height="50" style="position:relative;" src="' + url + '"/></td><td style="font-size:11px;font-weight:bold;min-height:20px;">'+ name + '</td></tr></table></span>';
//'<span id="name"><table style="width:260px;"><tr><td><img width="50" height="50" src="' + url + '"/></td><td><b style="font-size:12px;">' + name + '</b><br>' + kategory + '</td></tr></table></span>'
}
}
function onSelected() {
var i = $find("ace")._selectIndex;
var item = list.get_completionList().childNodes[i]._value;
$get("txtSearch").value = item.name;
}
</script>
i add a table it view like that(Table-2):
and finally its my ajax toolkit tag:
<asp:TextBox runat="server" ID="txtSearch" Width="261" />
<cc1:AutoCompleteExtender ID="txtSearch_AutoCompleteExtender" runat="server"
DelimiterCharacters="" Enabled="True" ServicePath="WebService.asmx"
FirstRowSelected="true"
EnableCaching="false"
ServiceMethod="GetResult"
MinimumPrefixLength="1"
CompletionListCssClass="completionList"
CompletionListHighlightedItemCssClass="itemHighlighted"
CompletionListItemCssClass="listItem"
OnClientItemSelected="onSelected" OnClientPopulated="onPopulated"
BehaviorID="ace" TargetControlID="txtSearch">
</cc1:AutoCompleteExtender>
How to create table like table-1? Please help me Thanks for your answers
I think, the following link may help you : http://vincexu.blogspot.com/2009/01/custom-autocomplete-6-multicolumn.html
For the record pasting code from the above mentioned article.
ASPX
<head runat="server">
<title></title>
<link href="../Default.css" rel="stylesheet" type="text/css" />
<style>
.cloumnspan
{
width:35px;
padding:0px;
border-color:Black;
border-style:solid;
border-width:1px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager runat="server" ID="ScriptManager1" />
<asp:TextBox runat="server" ID="myTextBox" Width="300" autocomplete="off" />
<ajaxToolkit:AutoCompleteExtender
runat="server" OnClientPopulated="dd" OnClientItemSelected="itemSelected"
BehaviorID="AutoCompleteEx"
ID="autoComplete1"
TargetControlID="myTextBox"
ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList5"
MinimumPrefixLength="2"
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="8"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :">
</ajaxToolkit:AutoCompleteExtender>
</form>
<script type="text/javascript">
function itemSelected(ev)
{
var index=$find("AutoCompleteEx")._selectIndex;
var value=$find("AutoCompleteEx").get_completionList().childNodes[index]._value;
$find("AutoCompleteEx").get_element().value = value;
}
function dd()
{
var comletionList=$find("AutoCompleteEx").get_completionList();
for(i=0;i<comletionList.childNodes.length;i++) {
var itemobj=new Object();
var _data = comletionList.childNodes[i]._value;
itemobj.name= _data.substring(_data.lastIndexOf('|') + 1); // parse name as item value
comletionList.childNodes[i]._value = itemobj.name;
_data = _data.substring(0, _data.lastIndexOf('|'));
itemobj.age = _data.substring(_data.lastIndexOf('|') + 1);
_data = _data.substring(0, _data.lastIndexOf('|'));
itemobj.id = _data.substring(_data.lastIndexOf('|') + 1);
comletionList.childNodes[i].innerHTML = "<div class='cloumnspan' style='width:10%;float:left'>" + itemobj.id + "</div>"
+ "<div class='cloumnspan' style='width:70%;float:left'>" + itemobj.name + "</div>"
+ "<div class='cloumnspan' style='width:18%;'>" + itemobj.age + "</div>";
}
}
</script>
</body>
Web Method:
[WebMethod]
public string[] GetCompletionList5(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
if (prefixText.Equals("xyz"))
{
return new string[0];
}
Random random = new Random();
List<string> items = new List<string>(count);
for (int i = 0; i < count; i++)
{
char c1 = (char)random.Next(65, 90);
char c2 = (char)random.Next(97, 122);
char c3 = (char)random.Next(97, 122);
int id = i;
int age = random.Next(18, 70);
items.Add(id.ToString() + "|" + age.ToString() + "|" + prefixText + c1 + c2 + c3);
}
return items.ToArray();
}