Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Using Control Properties in Embedded JavaScript Resource file

Reply
Thread Tools

Using Control Properties in Embedded JavaScript Resource file

 
 
hungrymind
Guest
Posts: n/a
 
      03-14-2008
Hi

I am trying to develop asp.net server control which has several
property in the control and has embedded javascript files, which is
used by control via webresource from the client page. I want to use
some of the property defined in controls main class inside the
javascript. at the same time I dont want to mess C# code and wants to
keep JS file seperate & clean. Is there anyway to access C# property
of control inside the javascript embeded file, like using <%=
PropertyName %>.

It will be something like this

document.getElementById('<%= this.ClientID%>')

I tried this, though I had doubt, and it did not worked. Can anyone
suggest the best way to achieve this, as well as keeping my C# &
javascript code in seperatly.

wishing in anticipation

hungryMind
www.hungrymind-concepts.com
 
Reply With Quote
 
 
 
 
digitaljeebus@gmail.com
Guest
Posts: n/a
 
      03-15-2008
There's absolutely no way to modify that jscript file before it gets
to the client, short of wrapping it in a generic handler, reading the
file, and writing it out while replacing chunks of code. I've found a
couple of ways around this. One would be to add a line in your OnLoad
event handler such as the following:

this.ClientScript.RegisterClientScriptBlock(this.G etType(),
"someuniquekey", string.Format("var temp =
document.getElementById('{0}');", this.ctrl.ClientId));

Another way (much cleaner way) would be to create a javascript class
using the asp.net ajax clientscript library. Here's a tutorial:

http://asp.net/ajax/documentation/li...ntScripts.aspx

Just a couple of options, none of them great =) Good luck!
 
Reply With Quote
 
 
 
 
hungrymind
Guest
Posts: n/a
 
      03-15-2008
thanks digital jee,

however i tried to initialize all c# property to javascript using
relection like this

Type type = this.GetType();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("var Map"+this.ID+" = new MyMap();");
foreach (PropertyInfo propertyInfo in
type.GetProperties())
{
if (propertyInfo.PropertyType == typeof(string))
{
stringBuilder.Append(" Map" + this.ID + "." +
propertyInfo.Name + " = '" + propertyInfo.GetValue(this, null) +
"';");
}
if (propertyInfo.PropertyType == typeof(double))
{
stringBuilder.Append(" Map" + this.ID + "." +
propertyInfo.Name + " = " + propertyInfo.GetValue(this, null) + ";");
}
}

return stringBuilder.ToString();

this has resolved my issue so far, but I wanted to keep JS & C#
absolutely seperate. I will look into second options, if it is not
only related with AJAX then it will work for me.

many thanks

hungrymind
www.hungrymind-concepts.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedded Resource File in Code Library called from ASP.Net web pag Jay Pondy ASP .Net 1 02-16-2009 08:02 PM
composite control embedded resource at designtime Chuck P ASP .Net Building Controls 1 09-25-2007 04:29 AM
Resource manager problem: naming for embedded resource. Dirc Khan-Evans ASP .Net 1 10-17-2005 12:52 PM
Databind an embedded control in an embedded datagrid Thomas Dodds ASP .Net Datagrid Control 0 07-26-2004 08:20 PM
Setting a WebForm (.aspx and source file) as an assembly Embedded Resource LidorP ASP .Net 1 11-22-2003 03:29 PM



Advertisments