Hi,
James Pemberton wrote:
Thank Laurent that pointed me in somewhat of a starting direction. I
originally had this script stored in an external JavaScript file in VS 2005
and the ClientID would not work, but I change my ASP page and imbedded the
script. When I then viewed it on the page it appeared to translate it
correctly.
So now my question is, how to I get my external script to work the same way?
Or can I?
I was referencing my other script like so:
<script src="Scripts/Goals_script.js" language="javascript"
type="text/javascript"></script>
Thanks
OK, now I understand your problem better. It's really an understanding
problem: You need to understand that only the ASPX page is processed by
the server, and the <%= ... %syntax will only work when written in the
ASPX page itself. All linked files (CSS, JavaScript) will not be processed.
What you can do however is use a variable to define the textbox's client
ID. Since every bit JavaScript on your page and also the scripts defined
in external files run in the same engine, you can define a variable in
the ASPX page and use it inside your external script. For example:
In the ASPX page:
string strScript = "<script type=\"text/javascript\">"
+ Environment.NewLine
+ "var strTextboxId = '" + tbProduct0.ClientID + "';"
+ Environment.NewLine
+ "</script>";
this.ClientScript.RegisterClientScriptBlock( typeof( YourPage ),
"TextboxIdScript",
strScript );
Then in the JavaScript file:
if ( strTextboxId )
{
var nTextbox = document.getElementById( strTextboxId );
if ( nTextbox
&& nTextbox.value )
{
// Use nTextbox.value
}
}
Sorry, didn't have time to test.
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering:
http://www.galasoft-LB.ch
Private/Malaysia:
http://mypage.bluewin.ch/lbugnion
Support children in Calcutta:
http://www.calcutta-espoir.ch