newbie_developer
newbie_developer

Reputation: 371

Javascript function to get values from C# fields or properties in ASP.Net

I’m new to JavaScript. Basically I want a function in JavaScript which will show me an email preview in a web browser. I’ve stored email’s template, body and contents.

SQL:

SELECT Name, template, body, contents FROM Email
WHERE EmailID = 1

C#: I have a LinkButton (ID="lnkViewDoc") on asp.net page and the code behind is:

lnkViewDoc.Attributes.Add("onclick", "return preview_email();");

JavaScript: I need a function please which will pick values from the class fields and show it in a web browser. thanks

function preview_email() {

  ..................
  window.open() //Something
}

Contents:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org   
/TR/xhtml1/DTD/xhtml1-transitional.dtd">  <html xmlns="http://www.w3.org/1999/xhtml">     
<head>      
    <title></title>  
</head>  
<body>
  <center>
      ..................
  </center>
</body>

Body:

<div style="text-align: left">   Dear .......,
    ...........................................
</div>  
<div style="text-align: left">   &nbsp;</div>  

Upvotes: 0

Views: 310

Answers (3)

Zachary Kniebel
Zachary Kniebel

Reputation: 4774

Take a look at the front-end server tags (bee stings). The ones I thing you're looking for are

<%=... %>

This is basically equivalent to Response.Write().

Upvotes: 1

Michiel Cornille
Michiel Cornille

Reputation: 2097

If you're not afraid of using jquery in your javascript newbie days, you can try to use Jquery Dialog like this:

$("<div></div>").load("previewEmail.ascx?emailid=5").dialog({autoOpen:true});

or something similar, you may want to consider just opening that same dialog with a iframe linking to the aspx, because your email will contain disturbing html elements like body tags

Upvotes: 0

Amiram Korach
Amiram Korach

Reputation: 13286

Suppose you have a .NET object named "email". In code behind write:

lnkViewDoc.Attributes.Add("onclick", "return preview_email(" + email.EmailID + ");");

In javascript:

function preview_email(emailid) {

  ..................
  window.open("previewEmail.aspx?emailid=" + emailid, ... more parameters)
}

Upvotes: 0

Related Questions