Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Thursday, October 12, 2017

Find position of object in the screen

Tested it, it works pretty nice in FF, Chrome, IE, Safari too.
function resetPosition(object, args) {
/* find the textbox object */
var tb = object._element;
/* measure textbox height */
var tbheight = tb.offsetHeight;
/* find textbox in the page */
var rect = tb.getBoundingClientRect();
var divleft = Math.floor(rect.left);
var divtop = Math.floor(rect.top + tbheight);
/* find the auto complete extender div in the page */
var ex = object._completionListElement;
/* move the ace to the right position */
if (ex)
$common.setLocation(ex, new Sys.UI.Point(divleft, divtop));
}

Friday, October 2, 2009

Disable browser's back button ?

you can disable the back button, they say.

didn't test the code yet, will be back with feedback





< script type="text/javascript">

function noBack(){window.history.forward()}
noBack();
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack()}
window.onunload=function(){void(0)}

< / script>






you can feedback also :)

Tuesday, June 30, 2009

Session state can only be used when enablesessionstate is set to true

I had a JavaScript function, that called a WebService, and I had this "Session state can only be used when enablesessionstate is set to true ..." error over and over again.

Everything was all right, in the web.config and in the "< % @ Page " too.

It was still giving me the error.

I made it work doing this:
start -- control panel -- administrative tools -- services -- asp.net state server

by default it is stopped. i started it.
that's it.

Wednesday, February 4, 2009

innerHTML not working in ie7

I had a bug
It looked like innerHTML is not working in ie7.
It was somthing like this:
function ShowLblError(msg)
{
document.getElementById("<%=lblError.ClientID%>").innerHTML = msg;
}

It worked fine in IE6, but not in IE7.
Finally I found out that it is working in IE7 too, I just had a panel with some weird height (it was ok in in IE6, ugly in IE7), and I just couldn't see the Label.

So innerHTML IS working in ie7
:)

Monday, September 1, 2008

Calling a server side from client's Javascript

Did you ever need something like calling a server side thing from client's? Javascript ... ?

I think this is an easy way of doing that:





Response.Write ( " < script language="javascript"> function SetPmoR_Id() { document.all('" + lkbPmoRepAdd.ClientID + "').click(); } < / script>")

//or:

ClientScript.RegisterClientScriptBlock(this.GetType(), "somethn", " < script type='text/javascript'> function whatdoyouwannacalit() { try {document.all('" + yourlinkbutton.ClientID + "').click();} catch(e){} } < / script>");






what do you think?

you think there's an easier way? comment!

Thursday, July 31, 2008

Parse html table cells

I wanted to parse a html table and color the TD - s (background).
All of them.
I have a column that has links in it. My basic Idea was to change the background color of the TD when you click the link inside that. That's easy, but without some global (js?) variable, you don't know what was previously clicked, and you might want to turn that "off" :)
Anyways: this is how I did it:





function ParseTableAndColorTheBackground(objTbl, WhatColorShouldItBe)
{
var intNrOfTrs = objTbl.tBodies[0].rows.length;
for (var i=0; i < intNrOfTrs; i++)
{
objTbl.tBodies[0].rows[i].cells[1].style.backgroundColor = WhatColorShouldItBe;
}
}




you have a better way to do this?

comment me pls
;)

Wednesday, April 16, 2008

Gridview rowcount from Js

I needed to get some rowcont in a Js variable, to have a google-like "select all" (all from all pages) button, that i didn't want to show up if there is only one page in my gridview.

Radu helped me out with this idea:
(I am using this on rowDataBound, because I didn't want to use an other event, I already had this one ...)




ScriptManager.RegisterClientScriptBlock(grvAgentCommissionFeePercentage, this.GetType(), "ScriptIDAndTicksForRefreshnumber" + DateTime.Now.Ticks.ToString(), "multiplePages = " + grvAgentCommissionFeePercentage.PageCount.ToString() + ";", true);




if you need the whole nine yards, just comment ... i'll get back to you

Thursday, April 3, 2008

Javascript - properties for any HTML object

Sometimes you need to see what properties can you use for any given object.
Just copy-paste this:



var stuff = '';
for (p in document.Form1.elements)
stuff = stuff + ' ' + p;
alert(stuff);



( ... and replace the document.form1.elements with anything you'd like. For example document.body, or document.getElementById("someTDfromYourTable"), etc. ...)