I am developing a application in C#, ASP.NET and I have a lot os divs in my page, each div is a container for a chat message and each div have a unique id: like this
"<div id='" + myMsgs[j].id_chat_message + "' style='padding: 10px;'>"
so, each div have the same id in page and in database.
now a want to find some div, with jquery, but it doesnt work
for (var j = 0; j < myMsgs.length; j++) {
findDiv = $('#<%= ' + myMsgs[j].id_chat_message + '.ClientID%>');
}
i know that my problem is the concatenation of the strings, but i dont know how to solve it.
When you try to use server tags in the aspx page like that, you are telling ASP .NET to process the page during rendering and replace all those tags with their corresponding values or evaluations. Since you're trying to build the string inside the server tags dynamically using JavaScript, ASP .NET isn't going to process that string and you'll end up with code like this:
$("#<%=id1.ClientID %>")
ASP .NET only processes this type of tag when it renders the page (which is already finished), and this is running on the client-side only, so this isn't going to work.
You should be able to just do this:
for (var j = 0; j < myMsgs.length; j++) {
findDiv = $('#' + myMsgs[j].id_chat_message);
}
the simplest approach would be: add a class-property, which you can then access via jQuery - eg.
var messageBoxes = $('.mySpecialCssClass');
you can now iterate over this array and do something with jQuery/javaScript!
According to your code "myMsgs" should be something like this (in javascript):
var myMsgs = [{"id_chat_message":"id1"},{"id_chat_message":"id2"},{"id_chat_message":"id3"}];
Which would mean this will let you get at the divs you want:
for(var j = 0, l = myMsgs.length; j < l; ++j){
$("#" + myMsgs[j].id_chat_message);
}
But there is probably a better way to do what you want.
Can you provide some more details?
Related
Scenario:
I have a calculated SQL that returns 100 results.
Added a table (from this calculated SQL) and limited the size of the page by 25 results.
This will generate 4 pages.
Pager form AppMaker works well (navigates between pages) but i need a button that navigates directly from page 1 to the page 4.
is this possible?
Anyone got a solution for this?
Regards
If you need to know how many entries your table has (in your case it's seems fixed to 100, but maybe it could grow), you can still do what you want:
E.g. say your table on YOURPAGE depends on a datasource called Customers.
Create a new Data item called CustomerCount, with just one field, called Count (integer).
Its data source would be a sql query script:
Select count(CustomerName) as Count from Customers
on the page you are having the table on, add a custom property (say called
Count of type integer)
In the page attach event, set the property asynchronously with this custom action:
app.datasources.CustomerCount.load(function() {
app.pages.YOURPAGE.properties.Count = app.datasources.CustomerCount.count;
app.datasources.Customers.query.pageIndex = #properties.Count / 25;
app.datasources.Customers.datasource.load();
});
I tried similar things successfully in the past.
Found a solution for this:
ServerScript:
function CandidateCountRows() {
var query = app.models.candidate.newQuery();
var records = query.run();
console.log("Number of records: " + records.length);
return records.length;
}
in the button code:
var psize = widget.datasource.query.pageSize;
var pidx = widget.datasource.query.pageIndex;
var posicao = psize * pidx;
var nreg = posicao;
google.script.run.withSuccessHandler(function(Xresult) {
nreg = Xresult;
console.log('position: ' + posicao);
console.log('nreg: ' + nreg);
console.log('psize: ' + psize);
console.log('pidx: ' + pidx);
var i;
for (i = pidx; i < (nreg/psize); i++) {
widget.datasource.nextPage();
}
widget.datasource.selectIndex(1);
}).CandidateCountRows();
This will allow to navigate to last page.
If you know for a fact that your query always returns 100 records and that your page size will always be 25 records then the simplest approach is to make sure your button is tied to the same datasource and attach the following onClick event:
widget.datasource.query.pageIndex = 4;
widget.datasource.load();
This question already has answers here:
How to identify unused CSS definitions from multiple CSS files in a project
(3 answers)
Closed 9 years ago.
I was thinking of writing a script which would tell me:
How often each CSS class defined in my .css file is used in my code
Redundant CSS classes - classes never used
CSS classes hat are referenced that don't exist.
But I just want to make sure something like this doesn't exist already? Does it?
Thanks
Just for fun, I wrote one.
try it
First we need to find our style sheet. In an actual script, this would be written better, but this works on jsFiddle.
var styles = document.head.getElementsByTagName('style');
var css = styles[styles.length - 1].innerHTML;
Then remove comments, and the bodies of each selector (i.e. the stuff between the brackets). This is done because there could be a .com in a background-image property, or any number of other problems. We assume there isn't a } in a literal string, so that would cause problems.
var clean = css.replace(/\/\*.*?\*\//g, '').replace(/\{[^}]*\}/g, ',');
We can find classes with regular expressions, and then count how many of them occur.
var re_class = /\.(\w+)/g;
var cssClasses = {}, match, c;
while (match = re_class.exec(clean)) {
c = match[1];
cssClasses[c] = cssClasses[c] + 1 || 1;
}
I used jsprint for displaying our findings. This shows how many times each class is mentioned in our CSS.
jsprint("css classes used", cssClasses);
Thanks to Google and this answer we can find all elements in the body, and loop through them. By default, we assume no classes were used in our HTML, and all classes used were defined.
var elements = document.body.getElementsByTagName("*");
var neverUsed = Object.keys(cssClasses);
var neverDefined = [];
var htmlClasses = {};
We get each elements class, and split it on the spaces.
for (var i=0; i<elements.length; i++) {
var e = elements[i];
var classes = (e.className || "").split(" ");
This is a three dimensional loop, but it works nicely.
for (var j=0; j<classes.length; j++) {
for (var k=0; k<neverUsed.length; k++) {
We thought classes[j] was never used, but we found a use of it. Remove it from the array.
if (neverUsed[k] === classes[j]) {
neverUsed.splice(k, 1);
}
}
It looks like we found a class that doesn't appear in our CSS. We just need to make sure it's not an empty string, and then push it onto our array.
if (classes[j].length && cssClasses[classes[j]] == null) {
neverDefined.push(classes[j]);
}
Also count the number of times each class is used in HTML.
if (classes[j].length) {
htmlClasses[classes[j]] = htmlClasses[classes[j]] + 1 || 1;
}
}
}
Then display our results.
jsprint("html class usage", htmlClasses);
jsprint("never used in HTML", neverUsed);
jsprint("never defined in CSS", neverDefined);
i have an application in which i have around 100 textinputs all are numbers
i want to simplify the addition ie. any other way than saying txt1.text+txt2.text.....
that would increase my code a lot
is it possible to have (n+=txt*.text) or some thing like that
any help would be appreciated have to get the application done in two days thank you
If txt1, txt2 etc are public properties of the class representing this, you can use the following code to get the sum of the numbers in the text inputs.
var n:Number = 0;
for(i = 1; i <= total; i++)
n += Number(this["txt" + i].text);
To get a concatenated string:
var s:String = "";
for(i = 1; i <= total; i++)
s += this["txt" + i].text;
If the text inputs are properties of a different class, use the instance name of the object instead of this. For example:
instanceName["txt" + i].text;
Another solution that is more clean is to store them in an array and loop through them. But that might require changes in other parts of your code.
I have a question about the Dynamics CRM 4.0 Webservice. I've been using it to get records from CRM into ASP.NET. After the request and the casting, the values of the columns (for instance for a contact) can be accessed through;
BusinessEntity be = getBusinessEntity(service, crmGuid, type, colnames);
contact tmp = (contact)be;
Response.Write("firstname: " + tmp.firstname + "<BR>");
Response.Write("lastname: " + tmp.lastname+ "<BR>");
I have an array of strings which identify which columns should be retrieved from CRM (colnames), for instance in this case {"firstname", "lastname"}.
But colnames can become quite big (and may not be hardcoded), so I don't want to go through them one by one. Is there a way to use something like
for(int i = 0; i < colnames.length; i++)
{
Response.write(colnames[i] + ": " + tmp.colnames[i] + "<BR>");
}
If I do this now I get an error that colnames is not a field of tmp.
Any ideas?
Not using BusinessEntity (unless you use reflection). DynamicEntity is enumerable by types deriving from Property. You'll have to do something like (I did this from memory, so might not compile)...
for(int i = 0; i < colnames.length; i++)
{
string colName = colnames[i];
foreach(Property prop in tmp)
{
if (prop.name != colName)
continue;
if (prop is StringProperty)
{
var strProp = prop as StringProperty;
Response.Write(String.Format("{0}: {1}<BR />", colName, strProp.Value));
}
else if (prop is LookupProperty)
{
...
}
... for each type deriving from Property
}
}
Reply to Note 1 (length):
Could you give me an example of what you're using. If you are only looking at the base types (Property) then you won't be able to see the value property - you'll need to convert to the appropriate type (StringProperty, etc).
In my example tmp is a DynamicEntity (it defines GetEnumerator which returns an array of Property). The other way to access the properties of a DynamicEntity is using the string indexer. For tmp:
string firstname = (string)tmp["firstname"];
Note that if you use this method, you get the Values (string, CrmNumber, Lookup) and not the whole property (StringProperty, CrmNumberProperty, etc).
Does that answer your question? Also, I recommend using the SDK assemblies and not the web references. They're much easier to use. The SDK download has a list of helper classes if you choose to use the web references, however. Search "Helper" in the SDK.
I making a web app in Flex using global coordinates
I get the coordinates as strings from a web service then I do something like this:
latStr:String = "28.7242100786401";
longStr:String = "-106.12635420984";
var cLat:Number = new Number(latStr);
var cLong:Number = new Number(longStr);
This works PERFECT on IE and chrome, from the web server and when debugging locally, but Firefox just works when debugging locally and not from the web server, in the web server cLat and cLong return "NaN".
check it out yourself, it should pop up an alert when you click on a result:
http://mundobuk.com/prueba/mapa/main.html?buscar=oxxo
so I tried using parseFloat(), but it rounds cLat to 28 and cLong to -106 :(
Then I tried separating the decimals form integers, like from my example 28 and 7242100786401 then divide 7242100786401/10000000000000 = 0.7242100786401
having 2 numbers 28 and 0.7242100786401 I add them up
28 + 0.7242100786401 = 28.7242100786401
here is in code form:
var latArr:Array = latStr.split(".");
var longArr:Array = longStr.split(".");
var latDivStr:String = "1";
for (var i:int= 0; i< latArr[1].length; i++){
latDivStr += "0";
}
var longDivStr:String = "1";
for (var j:int = 0; j< longArr[1].length; j++){
longDivStr += "0";
}
var cLat:Number = parseFloat(latArr[0]) + arseFloat(latArr[1])/parseFloat(latDivStr);
var cLong:Number = parseFloat(longArr[0]) - parseFloat(longArr[1])/parseFloat(longDivStr);
again, this way works great everywhere, just not in firefox in the web server >_>
anyone have any ideas? im going crazy whit this #_#
Comma is the separator for many European countries, so it's most likely the regional configuration on either the server or the client.
I have never hear of such an error as The Flash run-time is supposed to make the different browsers and OS's interpret the SWF the same way. I will say that I don't believe you should be using "new" in-front of your Number casting.
latStr:String = "28.7242100786401";
longStr:String = "-106.12635420984";
var cLat:Number = new Number(latStr);
var cLong:Number = new Number(longStr);
This should be:
var cLat:Number = Number(latStr); //Number is right because its a Floating Point, but remove new.
var cLong:Number = Number(longStr); //Number is right because its a Floating Point, but remove new.
I tested the using the following and saw no rounding take place.
var latStr:String = "28.7242100786401";
var longStr:String = "-106.12635420984";
trace(parseFloat(latStr)); //Outputs: "28.7242100786401";
trace(parseFloat(longStr)); //Outputs: "-106.12635420984";
trace(Number(latStr)); //Outputs: "28.7242100786401";
trace(Number(longStr)); //Outputs: "-106.12635420984";
I do not see why you require this workaround. Also I use firefox as my main browser and your site seems to be working just fine.
Cheers.
I finally found out why its not working, for some reason in firefox instead of reading a dot (.) it reads a comma (,) from the web service (done in vb.net)
locally it reads it as a dot too, not online, so I suppose it has to do something with my IIS server O_o
hope this helps someone out there...