How to get .net band object from javascript?

Hello,

We have created a band object through .Net 2.0. We need to get object of that band obect and access its method through javascript. The purpose behind is, without going to server and we should access .Net Objects functionality from client side itself. The .Net objects in the form of Band on the client's browser.

Could you give me the steps to achieve this task?

 

Thanks,

R.Umasankar 

 

 

0
sankar1984
7/8/2008 5:57:54 PM
asp.net.client-side 24353 articles. 1 followers. Follow

3 Replies
615 Views

Similar Articles

[PageSpeed] 5

I don't know what a "Band" object is, but the only things that you can pass back and forth to/from the server are strings, so you would need to convert your "Band" object into a string and pass it to the client.

Here's a simple example:

public class Band
{
 public string property1 = "";
 public string property2 = "";

 private Band(string prop1, string prop2)
 {
  property1 = prop1;
  property2 = prop2;
 }
 public override string ToString()
 {
  string outputText = string.Format(
   "{0},{1}",
   property1, property2);

  return outputText;
 }
}

<form id="Form1" method="post" runat="server">
 <input type="button" onclick="getBand();" value="Press Me">
 <input id="hiddenElement" type="hidden" name="hiddenElement" runat="server">
</form>

<script type="text/javascript">
<!--
function createBand()
{
 var bandArray = document.getElementById('').value.split(',');

 return { property1:bandArray[0], property1:bandArray[1] }
}
function getBand()
{
 var yourBand = createBand();

 alert('property1: ' + yourBand.property1);
 alert('property2: ' + yourBand.property2);
}
// -->
</script>

private void Page_Load(object sender, System.EventArgs e)
{
 Band yourBand = new Band("someValue");

 hiddenElement.Value = yourBand.ToString();
}

NC...

0
NC01
7/8/2008 7:02:27 PM

Hi Umasankar 


 

Just as NC said, the only way communicate between server-side and client-side is use String type, you can pass your “Band” object use JSON or XML format, JSON will be faster.


 

For more information about JSON:


 

http://en.wikipedia.org/wiki/JSON


 

http://www.json.com/


 

http://developer.yahoo.com/yui/json/


 

http://www.json.org/


 
If I’ve misunderstood your problem, please feel free to let me know.
 
Thanks.
 

 


Lance Zhang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Lance
7/11/2008 6:06:53 AM

You are right Lance, I just wanted to keep it as simple as possible for him.

NC...

 

0
NC01
7/11/2008 11:48:20 AM
Reply: