473,382 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

passing clientid t javascript from aspx declaration

Hi, I am wondering why the <%= % is not working when I use it to pass
the clientid to a javascrip function from the aspx declaration code.

Say, I have a listbox webcontrol and from its client-side javascript
eventhandler attribute, I try to pass on the client id as follows

<asp:ListBox ID="myListBox"
runat="server"
onchange="lst_onchange('<
%=myListBox.ClientID%>')" >
</asp:ListBox>

In the javascript as follows it will not show the actual clientid, but
will pass on the whole paramater without evaluating it simply as <
%=myListBox.ClientID%>

function lst_onchange(lstBoxID){
alert(listboxID)
}

Apr 16 '07 #1
3 18799


On Apr 16, 10:33 am, "Aamir Ghanchi" <aamirghan...@gmail.comwrote:
Hi, I am wondering why the <%= % is not working when I use it to pass
the clientid to a javascrip function from the aspx declaration code.

Say, I have a listbox webcontrol and from its client-side javascript
eventhandler attribute, I try to pass on the client id as follows

<asp:ListBox ID="myListBox"
runat="server"
onchange="lst_onchange('<
%=myListBox.ClientID%>')" >
</asp:ListBox>

In the javascript as follows it will not show the actual clientid, but
will pass on the whole paramater without evaluating it simply as <
%=myListBox.ClientID%>

function lst_onchange(lstBoxID){
alert(listboxID)

}- Hide quoted text -

- Show quoted text -
me again.
Never mind. I have done it in code behind pageload event handler by
adding the clientside ebenthandler to the listbox's attributes
collection and its working fine. But still, I would like to hear why
is it not possible to use <%=%or <% Response.write()%in the
clientside event handler attribute of a webcontrol.

thanks.

Apr 16 '07 #2
you can not use <%= %with server control properties, only databinding
expressions (<%# %>), but you must databind.

in your case you need neither, just use:

<asp:ListBox
ID="myListBox"
runat="server"
onchange="lst_onchange(this);" >
</asp:ListBox>

function lst_onchange(e){
alert(e.id);
}

-- bruce (sqlwork.com)

Aamir Ghanchi wrote:
Hi, I am wondering why the <%= % is not working when I use it to pass
the clientid to a javascrip function from the aspx declaration code.

Say, I have a listbox webcontrol and from its client-side javascript
eventhandler attribute, I try to pass on the client id as follows

<asp:ListBox ID="myListBox"
runat="server"
onchange="lst_onchange('<
%=myListBox.ClientID%>')" >
</asp:ListBox>

In the javascript as follows it will not show the actual clientid, but
will pass on the whole paramater without evaluating it simply as <
%=myListBox.ClientID%>

function lst_onchange(lstBoxID){
alert(listboxID)
}
Apr 16 '07 #3
On Apr 16, 11:44 am, bruce barker <nos...@nospam.comwrote:
you can not use <%= %with server control properties, only databinding
expressions (<%# %>), but you must databind.

in your case you need neither, just use:

<asp:ListBox
ID="myListBox"
runat="server"
onchange="lst_onchange(this);" >
</asp:ListBox>

function lst_onchange(e){
alert(e.id);
}

-- bruce (sqlwork.com)

Aamir Ghanchi wrote:
Hi, I am wondering why the <%= % is not working when I use it to pass
the clientid to a javascrip function from the aspx declaration code.
Say, I have a listbox webcontrol and from its client-side javascript
eventhandler attribute, I try to pass on the client id as follows
<asp:ListBox ID="myListBox"
runat="server"
onchange="lst_onchange('<
%=myListBox.ClientID%>')" >
</asp:ListBox>
In the javascript as follows it will not show the actual clientid, but
will pass on the whole paramater without evaluating it simply as <
%=myListBox.ClientID%>
function lst_onchange(lstBoxID){
alert(listboxID)
}- Hide quoted text -

- Show quoted text -
Thanks Bruce. I guess I oversimplified my example for this newspost.
I was aware of the "this" object in javascript which can be to
retrieve the reference to the element from which the eventhandler is
being called. But, I had another parameter in there which was an id
property of another webcontrol on the form.

Any ways, thanks very much for confirming that <%= %cannot be used
from within the webcontrol attribute value.

Apr 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: francois | last post by:
I would like to pass information between ASPX pages. For now, my navigation are hardcoded links. In some case I do a Response.Redirect("pages.aspx") Now I wonder is this is a good way to do. ...
2
by: vengala s reddy | last post by:
i have login.aspx, login.vb, i have my stored procedures in login.vb in login.aspx <%@ Page Language="vb" src="/MyTime/com/login.vb" Inherits="Enter.MyTime"%> in login.vb Public Sub...
0
by: Vibhu Bansal | last post by:
http://www.eggheadcafe.com/articles/20021207.asp I downloaded the sample from the above mentioned URL for passing Session variables from ASP to ASPX (actually I require the reverse of it) but...
3
by: michael | last post by:
let me keep it clean, quick and simple. I am passing a variable into another window and am reassigning the value on the new page - window.document...value = opener.document. ....value and...
5
by: Fernando Chilvarguer | last post by:
I'm sure this has come up before but I could not find any post on it. How can I read a variable or property that has been set on a ASPX page from inside a ASCX control. ASPX code: public...
4
by: =?ISO-8859-15?Q?Sven_K=F6hler?= | last post by:
Hi, look at this example: struct T1 { bool v; T1(bool p = false) { this->v = p; }
4
by: moondaddy | last post by:
I have a htm page where I need to pass some data to an aspx page as a means of sending data to the database. I don't need to see the aspx page so I was going to put it in a hidden iframe. This...
3
by: JJ | last post by:
I am using a handler (processImage.ashx) to display an image. The image is displayed according to parameters passed in the querystring. The handerl is called via some clientside javascript. I...
5
by: aelred | last post by:
I have a web page where a member can open up a chat window (child window) with another member. - From there the member can also navigate to other web pages. - From other pages in the site, they...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.