Thursday, March 29, 2012

setting Onclick and setting the ClientID in behind code isnt working in Mozilla

I'm reposting hoping to get a reply, my last one got bumped down
because I posted in the late day.

Hi,

I have in my behind code a user control with the following in Page
Load:

this.btn.Attributes.Add("onclick", "SetDivder(" +
this.divContainer.ClientID + ");");

In Internet Explorer I can press the button of the usr control and use
the object that is pass to the javascript function. In Mozilla, when I
click the button nothing happens.
For Mozilla if I remove the "this.divContainer.ClientID" and replace
it with"null" or just pass no parameters to the javascript function I
am then able to do alert('test'), but if I pass in at all
"this.divContainer.ClientID" to the javascript function the
alter('test'); will never fire. Is there a reason why you can't
predefine an object or what is being passed into the javascript
function in Mozilla, but can in Internet Explorere? Also, I have my
javascript function declared one time in the main.aspx page, so
dropping mutliple user controls on the same page will not create
multiple defintions of the javascipt function:

function SetDivder() //doesn't work if you put SetDivider(obj) and
pass in ClientID
{
alert('test')

}

Thanks,

DavidTry this:

this.btn.Attributes.Add("onclick", "SetDivder('" +
this.divContainer.ClientID + "');");

-- I put single quotes around the "this.divContainer.ClientID" - which is a
string.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"davidr@.sharpesoft.com" wrote:

Quote:

Originally Posted by

I'm reposting hoping to get a reply, my last one got bumped down
because I posted in the late day.
>
Hi,
>
I have in my behind code a user control with the following in Page
Load:
>
this.btn.Attributes.Add("onclick", "SetDivder(" +
this.divContainer.ClientID + ");");
>
In Internet Explorer I can press the button of the usr control and use
the object that is pass to the javascript function. In Mozilla, when I
click the button nothing happens.
For Mozilla if I remove the "this.divContainer.ClientID" and replace
it with"null" or just pass no parameters to the javascript function I
am then able to do alert('test'), but if I pass in at all
"this.divContainer.ClientID" to the javascript function the
alter('test'); will never fire. Is there a reason why you can't
predefine an object or what is being passed into the javascript
function in Mozilla, but can in Internet Explorere? Also, I have my
javascript function declared one time in the main.aspx page, so
dropping mutliple user controls on the same page will not create
multiple defintions of the javascipt function:
>
function SetDivder() //doesn't work if you put SetDivider(obj) and
pass in ClientID
{
alert('test')
>
}
>
Thanks,
>
David
>
>


That worked. Thank you! As I noticed in IE when you exclude the
singal qutoes it passes in the specific object. Mozilla doesn't
interpret the straight ClientID as an object. By adding the single
quotes the ClientID is passed in as a string and then I just leverage
the document.getelementbyID('test') to get the object and use it, which
both ID and Mozilla interpret.

Again,

Thanks,

David

0 comments:

Post a Comment