Asp .Net client side dynamic text - html

Im learning Asp.Net, after writing a master page, I couldnt make it run on client (to actually see the animation). The thread waiting action is done on server before publishing the web page so animation is not dynamic. It shows only the final state of the page.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body bgcolor="red">
<center>
<h2>Hello w3schools!</h2>
<h4 id="aa">qq</h4>
<h3>
<p><%
for (int i = 0; i < 30; i++)
{
System.Threading.Thread.Sleep(25);
int txtLeft = 300 + (int)(100*Math.Sin(i));
int txtTop = 300+(int)(100*Math.Cos(i));
string theText = "Hello there!";
Response.Write("<div style=\"position:absolute; left: "+ txtLeft + "px; top:" + txtTop + "px; \">" + theText +"</div>");
}
%></p>
</h3>
</center>
</body>
</html>
I tried
runat="client" (near the "p" letter which is in brackets)
but it failed:
Runat must have value Server.

Take a look at this jsFiddle:
$(Start);
function Start() {
var txtLeft, txtTop, theText, theHTML;
theText = "Hello there!";
for (var i = 0; i < 30; i++) {
txtLeft = 300 + (100 * Math.sin(i));
txtTop = 300 + (100 * Math.cos(i));
theHTML = '<div style="position:absolute; left: ' + txtLeft + 'px; top:' + txtTop + 'px;">' + theText + '</div>';
$('#Demo').append(theHTML);
}
}
Basically, there's no need for server-side programming to generate the output you want; use asp.net for server work. What you can do is add this script to the page in a script tag along with the jquery reference and you're done.

Related

Browser can not parse HTML properly - Grails 2

I am generating HTML from controller (Backend) but browser can not parse that HTML properly.
Controller code:
def getValue (returnIndex) {
String dropDown = "<select name='" + returnIndex + "' style=''>"
def CatArr = new BudgetViewDatabaseService().executeQuery("SELECT c.id,c.name AS categoryName FROM chart AS a LEFT JOIN crtClass AS b ON a.id=b.chart_class_type_id LEFT JOIN chart_group AS c ON b.id=c.chart_class_id WHERE c.status=1")
if (CatArr.size()) {
for (int i = 0; i < CatArr.size(); i++) {
def catId = CatArr[i][0]
def ProductArr
ProductArr = new BudgetViewDatabaseService().executeQuery("SELECT id,accountCode,accountName FROM bv.crtMsr where status='1' AND chart_group_id='" + catId + "'")
if (ProductArr.size()) {
dropDown += "<optgroup label='" + CatArr[i][1] + "'>"
for (int j = 0; j < ProductArr.size(); j++) {
dropDown += "<option value='" + ProductArr[j][1] + "' >" + ProductArr[j][1] + " " + ProductArr[j][2] + "</option>"
}
dropDown += "</optgroup>"
}
}
}
dropDown += "</select>"
return dropDown
}
view page's code:
<div class="fieldContainer fcCombo">
<label>
My GL <b>:</b>
</label>
${new CoreParamsHelperTagLib().getValue('formFourGLAccount')}
</div>
issue:
Generated HTML looks like:
When I am opening that HTML on edit mode from browser then its looks like:
<select name='formFourGLAccount' style=''><optgroup
label='Overige immateriële bezittingen'><option value='0430' >0430 Overige niet
materiële bezittingen</option></optgroup><optgroup label='Computers en
computerapparatuur'><option value='0210' >0210 Computers en
computerapparatuur</option><option value='0211' >0211 Afschrijving computers en
computerapparatuur</option></optgroup><optgroup label='Overige materiële
bezittingen'><option value='0250' >0250 Overige materiële
bezittingen</option><option value='0251' >0251 Afschrijving overige materiele
bezittingen</option></optgroup><optgroup label='Waarborgsommen'><option
value='0300' >0300 Waarborgsommen</option></optgroup><optgroup
label='Deelnemingen in andere bedrijven'><option value='0310' >0310 Aandeel of belang
in andere bedrijven</option></optgroup><optgroup label='Strategische langlopende
beleggingen'><option value='0320' >0320 Strategische langlopende
beleggingen</option></optgroup><optgroup label='Verstrekte langlopende leningen
(hypotheek ed)'><option value='0330' >0330 Verstrekte langlopende leningen (hypotheek
ed)</option></optgroup><optgroup label='Overige financiële
bezittingen'><option value='0340' >0340 Overige financiële bezittingen</option></optgroup><optgroup label='Voorraad'><option
If I copy returns result (HTML) from controller and past it on browser manually then its working fine
You have not shown how that HTML is being rendered so it isn't clear specifically how to fix it, but what is happening is the content is being HTML encoded, which you do not want if you want the browser to evaluate the HTML tags.
EDIT Based On Comment:
<div class="fieldContainer fcCombo">
<label>
My GL <b>:</b>
</label>
${new CoreParamsHelperTagLib().getGLAccountExpanseBudgetForReconcilationOthersDropDown('formFourGLAccount')}
</div>
There is no good reason to create an instance of a taglib. You should invoke the tag as a GSP tag.
You are returning hardcoded HTML from your controller as a model variable. That is a bad idea, but not what you are asking about. If you really do want to do that, then you will need to prevent the data from being HTML encoded in your GSP. You can use the raw(your unescaped html code here) method in your GSP as one way to avoid the encoding.

Outlook add-in - Insert HTML with background image

I have an outlook add-in that should insert HTML into an appointment. This can be done by calling:
item.body.setSelectedDataAsync
My problem is that I'm trying to insert HTML with a background image. This works fine when using Outlook in the browser, but the Outlook client requires workarounds using VML as described here:
https://www.emailonacid.com/blog/article/email-development/emailology_vector_markup_language_and_backgrounds
I guess item.body.setSelectedDataAsync strips the comments needed for VML (like <!--[if gte mso 9]> ) from the HTML passed to insert?
How can I accomplish adding HTML with background image from my add-in that works across different Outlook versions (browser and client)?
Below is example of javascript code used to insert HTML:
let htmlToInsert = '<table cellpadding="0" cellspacing="0" border="0" width="' + imageWidth + '" >';
htmlToInsert += '<tr><td style="text-align: center; font-size: x-large">' + this.props.roomMap.mapTitle + '</td></tr>';
htmlToInsert += '<tr><td valign="top" style="min-height:' + imageHeight + 'px;height:' + imageHeight + 'px; background-repeat: no-repeat; background-position: center bottom; width:' + imageWidth +';min-height:' + imageHeight + 'px;height:' + imageHeight + 'px;" background="' + this.props.roomMap.thumbnailUrl + '">';
htmlToInsert += '<!--[if gte mso 9]>';
htmlToInsert += '<v:rect style="width:' + imageWidth + 'px;height:' + imageHeight + 'px;" strokecolor="none">';
htmlToInsert += '<v:fill type="tile" src="'+ this.props.roomMap.thumbnailUrl +'" /></v:fill>';
htmlToInsert += '</v:rect>';
htmlToInsert += '<v:shape id="NameHere" style="position:absolute;width:' + imageWidth + 'px;height:' + imageHeight + 'px;">';
htmlToInsert += '<![endif]-->';
htmlToInsert += '<img src="https://www.meetingroommap.net/images/marker.png"/ style="margin-left:' + markerX + 'px; margin-top:' + markerY + 'px">';
htmlToInsert += '<!--[if gte mso 9]>';
htmlToInsert += '</v:shape>';
htmlToInsert += '<![endif]-->';
htmlToInsert += '</td></tr>';
htmlToInsert += '<tr><td style="text-align: center; font-size: xx-small">Powered by <a target="_blank" href="https://www.meetingroommap.net" >www.MeetingRoomMap.net</a></td></tr>';
htmlToInsert += '</table>';
console.log(htmlToInsert);
item.body.setSelectedDataAsync(
htmlToInsert,
{ coercionType: Office.CoercionType.Html,
asyncContext: { } },
function (asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Failed){
console.log("Error calling item.body.setSelectedDataAsync: " + asyncResult.error.message);
}
else {
// Successfully set data in item body.
}
});
Thank you for your feedback. After further investigation, it appears there's no great workaround to achieve your scenario. We continue to learn about the new requirements add-in developers have, which helps us enable great scenarios on our platform. We track Outlook add-in feature requests on our user-voice page. Please add your request there. Features on user-voice are also considered when we go through our planning process.
Link to user voice: https://officespdev.uservoice.com/forums/224641-general/category/131778-outlook-add-ins.
Thanks again for your feedback,
Outlook Add-ins Engineering Team

send value from client side to server side using C# in asp.net

I'm trying to create a website content management using asp.net and C# and bootstrap. I already done this using asp.net and C# and a server control like gridview but I want create this version one like as wordpress CMS.
I will describe my project to clear my purpose.
First I fill a DataTable from database. This Datatable has messageId int, Subject varchar, name varchar, email varchar, message text, isRead bit, and so on columns.isRead column is bit type for specifies that the message is read or not.
I Fill my DataTable using below Method:
DataTable dt = cls.Fill_In_DataTable("MessageFetchMessage");
Then I generate html text using another method dynamically: on Page_Load
protected void Page_Load(object sender, EventArgs e)
{
messeges = cls.fetchMessages();
}
messege the string variable, will append generated html code to aspx page:
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-clock-o fa-fw"></i> Last messages From users</h3>
</div>
<div class="panel-body">
<div class="list-group">
<%=messeges %>
</div>
<div class="text-right">
View All messages <i class="fa fa-arrow-circle-right"></i>
</div>
</div>
</div>
</div>
the message content has these text from fetchMessages()method:
public string fetchMessages()
{
string post = ""; string readed = "";
DataTable dt = cls.Fill_In_DataTable("MessageFetchMessage");
if (dt.Rows.Count>0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
DateTime dtTemp = DateTime.Parse(dt.Rows[i]["messageDate"].ToString());
if (dt.Rows[i]["isRead"].ToString() == "True")
readed = "MessageReaded";
else
readed = "MessageNew";
post += "<div class='modal fade' id='myModal" + dt.Rows[i]["messageId"].ToString() + "' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'>"
+ "<div class='modal-dialog' role='document'>"
+ "<div class='modal-content'>"
+ "<div class='modal-header'><button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>×</span></button><h4 class='modal-title' id='myModalLabel'><span style='font-weight:bold'>Subject</span> : " + dt.Rows[i]["subject"].ToString() + "</h4></div>"
+ "<div class='modal-header'><p><span style='font-weight:bold'>Date</span> : " + dtTemp.ToString("yyyy/MM/dd") + "</p>"
+ "<p><span style='font-weight:bold'>Time</span> : " + dt.Rows[i]["messageTime"].ToString() + "</p>"
+ "<p><span style='font-weight:bold'>Email</span> : " + dt.Rows[i]["email"].ToString() + "</p></div>"
+ "<div class='modal-body'>" + dt.Rows[i]["message"].ToString() + "</div>"
+ "<div class='modal-footer'><button type='button' class='btn btn-default' data-dismiss='modal'>Close</button><input type='submit' ID='btn" + dt.Rows[i]["messageId"].ToString() + "' class='btn btn-danger' onserverclick='btn_Click' value='Delete message' /></div>"
+ "</div></div></div>";
string narrow = Special.TimeToNarrow(dt.Rows[i]["messageDate"].ToString(), dt.Rows[i]["messageTime"].ToString());
post += "<a data-toggle='modal' data-target='#myModal" + dt.Rows[i]["messageId"].ToString() + "' href='#' class='list-group-item " + readed + "'><span class='badge'>" + narrow + "</span><i class='fa fa-fw fa-comment'></i> <span>"
+ dt.Rows[i]["name"].ToString() + "</span> : <span>" + dt.Rows[i]["subject"].ToString() + "</span></a>";
}
}
return post;
}
finally I add server code behind for btn_Click Event:
protected void btn_Click(object sender, EventArgs e)
{
string id = (sender as Control).ClientID;
//Then give Id to database class for CRUD Intractions
}
but btn_Click never called from client side. I search for similar question within 2 days and didn't get answer. please help me :)
Here I will put my Website screen Shots:
Then after click on one of the rows a pop up window will show using modal bootstrap:
Add your Modal, button and any other mark up you have to the ASPX page (mark up). Then you can get your ID on click event. The dynamic generation of your code is not registering the controls with the server side in Webforms.
Once you have captured your Message ID, you can place it in ViewState, Session or a hidden field on the UI. That way you can have the ID to use whenever you need it.

'data:post-snippet' truncation in blogger

Let's say I wrote a post like this on Blogger:
abc def ghi <div class="pls-exclude-from-snippet">jkl mno pqr stu vwxyz</div>
Instead of listing from a to z, I want Blogger to set its data:post.snippet to 'abc def ghi' only (letting Blogger know to stop if it reads the token: a div with class 'pls-exclude-from-snippet'). How do I do that?
I found help here https://productforums.google.com/forum/#!topic/blogger/X9LxrjXnb2s
Still have to tweak it a little, but it works. Think gonna post it to help people with similar problem as I had.
Here's my code. Before </head>, add:
<script type='text/javascript'>
//<![CDATA[
function stopIfFound(strx,token){
var theLocation = strx.indexOf(token);
if(theLocation!=-1){
strx = strx.substr(0,theLocation);
}
return strx;
}
function removeHtmlTag(strx, chop){
strx = stopIfFound(strx,'<div class="pls-exclude-from-snippet">');
if(strx.indexOf("<")!=-1){
var snippet = strx.split("<");
for(var i=0;i<snippet.length;i++){
if(snippet[i].indexOf(">")!=-1){
snippet[i] = snippet[i].substring(snippet[i].indexOf(">")+1,snippet[i].length);
}
}
strx = snippet.join("");
}
chop = (chop < strx.length-1) ? chop : strx.length-2;
while(strx.charAt(chop-1)!=' ' && strx.indexOf(' ',chop)!=-1) chop++;
strx = strx.substring(0,chop-1);
return strx+'...';
}
function createSnippet(pID){
var div = document.getElementById(pID);
var summ = snippet_count;
var summary = '<div class="snippets">' + removeHtmlTag(div.innerHTML,summ) + '</div>';
div.innerHTML = summary;
}
//]]>
</script>
Find <data:post.snippet/>, in
<div class='post-body'>
<b:if cond='data:post.snippet'>
<data:post.snippet/>
</b:if>
</div>
replace it with
<div expr:id='"summary" + data:post.id'><data:post.body/></div>
<script type='text/javascript'>createSnippet("summary<data:post.id/>");
</script>
You can try to limit the length of the characters.
Use this syntax:
<b:eval expr='snippet(data:post.body, {length: 150})' />
150 is the length. You can change it to any numbers you want.
Check my personal blog change snippet length on Blogger without Javascript to see more example.

displaying products in jsp as a grid

i'm trying to display my database content on a grid like this one:
grid example
I'm getting all products on one vertical colmun like this:
my products display
products are inserted in the array"Arrayp" ,right now i can diplay database content on vertical table or horizontal table but not on a grid like mentioned, this is my code and i would appreciate a help
<TABLE >
<%
while (cmp<=size )
{
out.println("<tr>");
out.println("<td>");
out.println("<p><img src=\"images/" + Arrayp.get(cmi) + " \" width=\"100\" height=\"100\" /></p>");
out.println("<p> categorie " + Arrayp.get(cmp) + "</p>");
out.println("<p> prix " + Arrayp.get(cmpri) + "</p>");
out.println("<p>quantité disponible " + Arrayp.get(cmpqt) + "</p>");
out.println("<form name='f' action='panier' method='post'>");
out.println("<input type='hidden' value= "+Arrayp.get(cmbref) +" name='ref' >");
out.println("<p>quantité desirée</p>");
out.println("<p><input type='text' name='nbr' ></p>");
out.println("<input type='submit' value='ajouter au panier' />") ;
out.println ("</form>");
cmp=cmp+8;
cmi=cmi+8;
cmpqt=cmpqt+8;
cmbref=cmbref+8;
out.println("<p></p>");
out.println("<p></p>");
out.println("</td>");
out.println("<tr>");
%>
</TABLE>
Use a counter to count items and when 4 item crossed add a new <tr> tag. Where now you adding <tr> tag for each item. Below i have give example, you can modify as you need.
Like:
<html>
<head>
tr {
display: block;
border: 1px solid blue;
}
td{
border: 1px solid red;
padding: 8px;
}
</style>
</head>
<body>
<%
int start = 0;
int elementsLen = 10;
int counter = 1;
int noOfItemsInRow = 4; //set number of td you want in tr
StringBuilder sb = new StringBuilder();
noOfItemsInRow++;
//start table
out.println("<table>");
while(start<=elementsLen){
sb.append("<td>");
sb.append(start);
sb.append("</td>");
//check if noOfElemntsInRow elements is reached keep it in a new row
if(++counter==noOfItemsInRow){
out.println("<tr>");
out.println(sb.toString());
out.println("</tr>");
sb.setLength(0);
counter = 1;
}
start++;
}
//print remaining td elements in a new row
if(sb.length()>1){
out.println("<tr>");
out.println(sb.toString());
out.println("</tr>");
}
//close table
out.println("</table>");
%>
</body>
</html>
Output:
Note: this is not a good idea to use scriptlets in jsp, instead you should use jstl.
I have it working now , i tried before with the if and it didnt work properly.
bizarrely i tried it today without closing the tr i mean without /tr in the end and it works and i got a clean grid :D
update : the problem was solved by closing the TR outside of the while loop, thx to all
here is the working code
int c =0;
int numberofcolumns=4;
%>
<TABLE>
<%
while (cmp<=size )
{
c++;
if (c==numberofcolumns){
numberofcolumns=numberofcolumns+3;
out.println("<tr>");
}
out.println("<td>");
out.println("<p><img src=\"images/" + Arrayp.get(cmi) + " \" width=\"100\" height=\"100\" /></p>");
out.println("<p> categorie " + Arrayp.get(cmp) + "</p>");
out.println("<p> prix " + Arrayp.get(cmpri) + "</p>");
out.println("<p>quantité disponible " + Arrayp.get(cmpqt) + "</p>");
out.println("<form name='f' action='panier' method='post'>");
out.println("<input type='hidden' value= "+Arrayp.get(cmbref) +" name='ref' >");
out.println("<p>quantité desirée</p>");
out.println("<p><input type='text' name='nbr' ></p>");
out.println("<input type='submit' value='ajouter au panier' />") ;
out.println ("</form>");
out.println("<td>");
cmp=cmp+8;
cmi=cmi+8;
cmpqt=cmpqt+8;
cmbref=cmbref+8;
out.println("<p></p>");
out.println("<p></p>");
}//
out.println("</tr>");
%>
</TABLE>