How to access global variable in htm page - jtemplate(jquery) - c#

I am using jtemplate(jquery) , in which i have a htm file as below
<table width="100%" border="0" cellpadding="0" cellspacing="2">
<tr class="dark_color">
<th>
Offer
</th>
</tr>
{#foreach $T.TransList as record}
<tr class="{#if ($T.record$index % 2) == 0} white_left {#else} dark_color {#/if}">
<td class="offer" align="left">
{$T.record.OfferName}
</td>
</tr>
{#/for}
</table>
I am filling data using below code in my aspx page -
$("#jtemplateGrid_" + lastID).setTemplateURL('JTemplate/gridTemplate.htm');
// process the template
$("#jtemplateGrid_" + lastID).processTemplate(data)
;
Now i want to use global variable in my htm page.
How we can done the same.
Thanks in advance

What you could do is to send a get parameter with it and split it using JavaScript or whatever you'd like on the page to check up on it or use it.
Not clear on how it could be done otherwise but it is a possibility.

Related

Get client side HTML changes on postback

I want to add rows to a table with javascript, but I also want to be able to find out what those rows are on postback. Is there a way to do that?
I also want to be able to populate the original rows in the table from the server (I'm thinking with a repeater). Is it still possible to do that?
That's not much of a description but I think that covers it...
The code currently looks something like this
<table id="myTable">
<tr> <td> some static row </td> </tr>
<asp:repeater id="rptTest" runat="server">
<HeaderTemplate>
<tr class="dgheader">
<th> head1 </th>
<th> head2 </th>
<th></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="<%# (Container.ItemIndex%2 == 0) ? "dgitem" : "dgalternatingitem" %>">
<td><%# Eval("val1") %> </td>
<td><%# Eval("val2") %> </td>
<td><a class="dgdeletebutton" href="javascript:delete(this)"></a></td>
</tr>
</ItemTemplate>
</asp:repeater>
</table>
At the moment all I'm wondering is how, server side, I can get a version of the table that has whatever changes I made client side.
In order to get any information from a client in the manner you describe, you need to include a field in your form submit.
You will probably want hidden(s) field. Any time you add a row, either add a hidden field for each value you want to capture (such as val1 and val2) or have one hidden field, and when you add a row, append the information you want to the existing row.
I would warn against posting straight html, you probably only need the values not the full markup, and you most likely don't want to sanitize the html and parse it for the information you want.
So to get you a head start you can add hidden inputs:
<tr class="<%# (Container.ItemIndex%2 == 0) ? "dgitem" : "dgalternatingitem" %>">
<input type="hidden" name="Row[1].val1" value="myvalue" />
<td><%# Eval("val1") %> </td>
<input type="hidden" name="Row[1].val2" value="myvalue" />
<td><%# Eval("val2") %> </td>
<td><a class="dgdeletebutton" href="javascript:delete(this)"></a></td>
</tr>
You can then get the submitted values on the backend:
HttpContext.Current.Request.Form["Row[1].val1"]
This is from memory, the line above might not be correct.

twitter bootstrap table css

i am developing an asp.net c# application using the twitter bootstrap framework.
i am trying not to add change or add any CSS so wanted to know the following
i have a asp.net gridview, which eventually renders as table. i wanted to know what is the css class to be applied for tables?
ASP.NET
C#
Twitter Bootstrap
<table cellspacing="0" rules="all" border="1" id="VideoList" style="border- collapse:collapse;">
<tr>
<th scope="col"> </th><th scope="col"> </th>
</tr><tr>
<td>Senior Care</td><td>
</td>
</tr><tr>
<td>Cardiac Catheterization Lab</td><td>
</td>
</tr>
</table>
any ideas will be much appreciated.
Well the minimum styling can be added just with the "table" class. That is:
MyGrid.CssClass = "table";
Optionally, you can include additional table formatting such as
MyGrid.CssClass = "table table-striped table-bordered";
To see some more noticeable styling

How do I create an email template within my application [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Razor views as email templates
I am sending out an email to the user from within my service of my website.
I want to format this so that it shows nice and a specific way.
Here is what I have:
<table bgcolor="#FFE680" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td width="100%" height="51" valign="middle"><h1> <strong>[COMPANY] User ID Reminder </strong></h1></td>
<td align="right" valign="top" width="8"><img alt="" width="8" height="8" align="top" /></td>
</tr>
</tbody>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td align="left" valign="top" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td colspan="1" align="left"></td>
</tr>
<tr>
<td align="left" valign="top" width="100%"><p> <br />
Dear [USERNAME], </p>
<p> In response to your request to be reminded of your User ID, please find below the information we have on file for you. If you didn't submit this request, ignore this email. </p>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>Your User ID is: </td>
<td>[USERNAME]</td>
</tr>
<tr>
<td>Your registered email address is:  </td>
<td>[EMAIL]</td>
</tr>
</tbody>
</table>
<p>
If you have forgotten your password, you can request it here.<br />
</p>
<p>
Thank you,<br />[COMPANY]
</p></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
Now my question isn't about the looks of the email but how do I put this as the body of my email while populating the appropriate fields?
I put it in resources as a string and I figured I'd just do a replace of the specific [fields]. This starting becoming tedious and seemed sloppy:
var body = SuburbanHUB.Properties.Resources.ForgotPasswordEmailBody.Replace("[USERNAME]", username).Replace("[EMAIL]")...
I'm sure there is a better way of doing this but I have not the experience.
=== CLARIFICATION ===
I am using razor to call a WCF service written in C#. The service that is being called is where the email is being sent from and not the view. I am using Razor with MVC with C# as the underlying code.
I'm in the middle of trying to do the same thing. We're using Razor templates to generate the email, and passing in a Model which has all the various variables to fill it out. This lets us include everything that Razor and MVC support, including #if and #Html.Partial, which lets us construct an email from pieces.
The answer we just went with involves running an internal MVC webserver, requesting pages from it with the Model as a parameter, and capturing the response text, but there's variants on my question that are more self contained. Take a look and see if any of the other answers or comments help you.
I had similar requirement and I end up using NVelocity and it worked great for me. Please see this article for a workthrough http://www.codeproject.com/Articles/12751/Template-merging-with-NVelocity-and-ASP-NET. You have to modify your fields in the template according to the velocity templating language. Download NVelocity from http://nvelocity.sourceforge.net/.

Error in table when adding runat=server

I have a html table in my ASPX page and would like to use it in code-behind for some processing. The table is shown as below:
<table class="hovertable" id="tblData">
<tr>
<th>ID:</th>
<td colspan="3" style="font-weight: bold">
<%= Eval("ID") %>
</td>
</tr>
<tr>
<th>Date:</th>
<td><%# Eval("Date", "{0:dd-MMM-yyyy}") %></td>
<th>Amount:</th>
<td><%# Eval("Amount", "{0:C}") %>
</tr>
</table>
However, when I add the runat="server" attribute to my table, I am produced with the following error:
CS1502: The best overloaded method match for 'System.Web.UI.HtmlControls.HtmlTableRowCollection.Add(System.Web.UI.HtmlControls.HtmlTableRow)' has some invalid arguments
Any ideas what may be wrong here? Am I missing out anything?
An html table (which is not a pure asp.net server control) can't contain asp.net server controls. Take a look at this answer:
http://forums.asp.net/t/1524580.aspx/1
In my opinion, you should ask yourself the following question?
Do i need to solve this client or server side?
if your answer is client, you should implement the update logic with Ajax, otherwise you could use the ASP.NET server control and implement it server side.
OK guys, I have solved this issue by myself. The problem causing it was because of a <td> not having the corresponding <tr> element.
It was something like below:
<table class="hovertable" id="tblData">
<tr>
<th>ID:</th>
<td colspan="3" style="font-weight: bold">
<%= Eval("ID") %>
</td>
</tr>
<tr>
<th>Date:</th>
<td><%# Eval("Date", "{0:dd-MMM-yyyy}") %></td>
<th>Amount:</th>
<td><%# Eval("Amount", "{0:C}") %>
</tr>
<td colspan='4'>
Some data....
</td>
</table>
I think you can use this for the same purpose
<asp:Table ID="Table1" runat="server">
</asp:Table>
What you are trying to do is adding runat="server" attribute to a HTML control
Try adding <asp:Labels> where you need to manipulate data.
<table>
<tr><td><asp:Label id="lblRow" runat="server" /></td></tr>
</table>
Table columns and rows cannot be accessed via code behind if you have runat="server" in the tag because they are pure html.
Another way is to use a StringBuilder to create the html table in the code-behind and and asp:LiteralControl to output the table.
Also if we remove the tbody element it will not throw error for td mismatch
Nikhil Mittal
Remove the below elements
<thead>
</thead>
<tbody>
</tbody>

Insert data into asp.net table through code

I have a table in asp.net page and i want to insert the data which will be recieved from service call through c# code behind. Any idea on how to do this.
Below is my table.
<table id="DataTable" class="style1">
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
I just need to insert values recieved from service call in place of &nbsp.
In your aspx page asp:Label controls and assign the values from code behind by accessing them using Id.
Inside .aspx
<asp:Label Id="lblName" runat="server">
In code behind
lblName.Text = "Value from Service";
If you need to repeat this table use GridView.
Use the asp:Table control instead.. It gives you much more control from server side than a normal html tag :)
And it ofc render as a normal table client side
If you persist on working with pure html table you can use an new/old style to control it.
like so:
<table>
<% foreach ( var o in objects ) { %>
<!--UserControl -->
<tr>
<td> can put here data like so: <%= o.Id %> </td>
</tr>
<!--UserControl -->
<%}%>
</table>
or you can use Repeater and Bind data if it's dynamic.
If data is not dynamic and your table will not grow or change size, you can use a little OOP for this.
like so:
create in your class properties and then populate them.
public string MyLabel { get; set; }
put something in page load.
in aspx do it like so..
<table>
<tr>
<td> <%= MyLabel %> </td>
</tr>
</table>
or
<table>
<tr>
<td> <asp:Label ID=|"myText" runat="server"/> </td>
</tr>
</table>
Make the table Html server side control. Try this:
<table runat="server" id="DataTable" class="style1">
<tr>
<td id="td1" runat="server">
</td>
<td id="td2" runat="server">
</td>
<td id="td3" runat="server">
</td>
<td id="td4" runat="server">
</td>
</tr>
Now in the code behind
td1.InnerText="xx" or td1.InnerHtml=..

Categories

Resources