asp:hyperlink not rendering correct HTML on server - c#

I'm working on a project that is in ASP.NET WebForms on .NET 2.0 and am running into a problem I can't seem to find a cause for. I have the following code in my aspx file:
<table>
<tr>
<td>
<asp:HyperLink ID="supportLink" runat="server">Customer Support Docket</asp:HyperLink>
</td>
</tr>
<tr>
<td>
<asp:HyperLink ID="entitlementsLink" runat="server">Edit Entitlements</asp:HyperLink>
</td>
</tr>
</table>
And when I run locally in debug mode, it works great. The links appear and the HTML is rendered properly as such:
Local Rendered HTML
<table>
<tr>
<td>
<a id="ctl00_ContentMain_supportLink" href="ViewCustomer.aspx?customerid=659">Customer Support Docket</a>
</td>
</tr>
<tr>
<td>
<a id="ctl00_ContentMain_entitlementsLink" href="EditEntitlements.aspx?customerid=659">Edit Entitlements</a>
</td>
</tr>
</table>
However, when I run it on my server in production, I get the following HTML generated:
Server Rendered HTML
<table>
<tr>
<td>
<a id="ctl00_ContentMain_supportLink">Customer Support Docket</a>
</td>
</tr>
<tr>
<td>
<a id="ctl00_ContentMain_entitlementsLink">Edit Entitlements</a>
</td>
</tr>
</table>
As you can see, the href is missing from both. In my code behind I am adding the URLs since I was having a hard time getting them to render properly in the aspx file:
Code Behind File
protected void Page_Load(object sender, EventArgs e)
{
supportLink.NavigateUrl = string.Format("ViewCustomer.aspx?customerid={0}",
Request.QueryString["customerid"]);
entitlementsLink.NavigateUrl = string.Format("EditEntitlements.aspx?customerid={0}",
Request.QueryString["customerid"]);
}
At this point I'm not sure what I can do. My plan was to re-write this site in the next few weeks in MVC4 but seeing as this is an internal site and not generating money it is low on my priorities list and won't get much more attention for awhile, which means I need to fix this issue.
The server environment is IIS 6 on Windows Server 2003 and the HTML renders this way in both IE9 as well as Chrome 24.0.1312.57. I have cleared the cache in both browsers to no avail and I know that the page is getting updated after a publish because other features that I added with the same change are actually working in production.
EDIT
Rezalas was wondering where I got the customerid from. It is from the query string. To show that a blank query string wouldn't cause this here is the local and production HTML with no query string:
Local Rendered With No Query String
<table>
<tr>
<td>
<a id="ctl00_ContentMain_supportLink" href="ViewCustomer.aspx?customerid=">Customer Support Docket</a>
</td>
</tr>
<tr>
<td>
<a id="ctl00_ContentMain_entitlementsLink" href="EditEntitlements.aspx?customerid=">Edit Entitlements</a>
</td>
</tr>
</table>
Production HTML With No Query String
<table>
<tr>
<td>
<a id="ctl00_ContentMain_supportLink">Customer Support Docket</a>
</td>
</tr>
<tr>
<td>
<a id="ctl00_ContentMain_entitlementsLink">Edit Entitlements</a>
</td>
</tr>
</table>

For clarification, where is the customerid value coming from? Are you certain that the value when ran on the server is being properly pulled? I say this because it looks as though the ID isn't being provided, and as such the string isn't being built and the navigate url is being excluded because it doesn't have a value.

Related

Several submit buttons with different Id but same action

I have a shopping cart form with any number of items (products). For each item, there is a delete-button. At the bottom of the form, there is an update-quantities-button. Each of the delete-buttons should post "delete" and Id. The update-button should post "update" and the entire array of values from the input fields.
I have spent some time googling for answers, but every mention of "multiple submit buttons in one form" I could find, refers to different actions per button. I want to point to the same action, but with a different Id for each button. That means I cannot use asp-action="someAction" asp-route-id="someId" in the FORM-tag.
My questions:
1) How to send action and Id to the controller (for delete item)? If I put the Id inside value="" in the button-tag, the Id will be displayed on the button. I don't want that.
2) How to send the array of values from all the item's quantity input-field, and how to match each value to the appropriate Id (in the action method)?
This is my cart:
<form>
<table>
#foreach (var item in Model.ShoppingCartItems)
{
<tr>
<td nowrap>
<a asp-action="Details" asp-route-id="#item.ProductId">
#item.ProductTitle
</a>
</td>
<td nowrap>
#Html.DisplayFor(Model => item.ProductPrice)
</td>
<td nowrap>
<input asp-for="#item.Quantity" value="#item.Quantity" />
</td>
<td nowrap>
#Html.DisplayFor(modelItem => item.LineSum)
</td>
<td>
<button type="submit" formaction="Delete">Delete</button>
</td>
</tr>
}
<tr>
<td colspan="3"><strong>Sum</strong></td>
<td nowrap><strong>#Html.DisplayFor(model => model.TotalSum)</strong></td>
<td></td>
</tr>
<tr>
<td colspan="3">
<button type="submit" formaction="Update">Update quantities</button>
</td>
<td colspan="2">
<a asp-action="Checkout">Go to checkout</a>
</td>
</tr>
</table>
</form>
The action methods haven't been written yet. I'm not expecting anyone to code for me, I just need a nudge in the right direction. :)
You don't have to make it type="submit". you can make it normal Ajax request.
(1) you can add id in attr (ex: data-id = "#Id") and make javascript ajax call when press delete call this function and read attr value.
(2) you can pass an array in JSON format
read more from here
https://www.codeproject.com/Questions/834557/Pass-an-array-to-MVC-Controller-from-ajax
How to pass Array to MVC Controller with Jquery?

Get data from tabel [HTML] into SQL database

I would like to create a program that gets data from the play.eslgaming.com website and puts this into a database.
I already found out that the data I need is just in the raw code of the webpages. Like following:
<div id="round-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
<span class="teamstatus">Team: Evil Squirrels <small><i>(Attacker)</i></small></span>
<table class="wot_stats">
<tbody class="matchloser">
<tr>
<th>Tank</th>
<th>Player</th>
<th>Kills</th>
<th>Dmg dealt</th>
<th>Remain. HP</th>
<th>Blocked dmg</th>
<th>Time alive</th>
<th>Shots fired</th>
<th>Accuracy</th>
</tr>
<tr>
<td>
<div class="tank">
<img src="http://static-ptl-eu.gcdn.co/static/2.34.2/encyclopedia/tankopedia/vehicle/contour/ussr-object_140.png" class="icon-img">
<em>U.S.S.R. Object 140</em>
</div>
</td>
<td>
<div class="playername">
<a target="_blank" style="cursor: pointer;" href="/worldoftanks/europe/wot/open/bronze-series/player/7176461">conchita_</a>
<em>Conchita_</em>
</div>
</td>
<td>2</td>
<td>2781</td>
<td>Destroyed</td>
<td>240</td>
<td>07m 34s</td>
<td>18</td>
<td>50%</td>
And so on for each player each round 2 teams.
But the problem now is that I don't know how I get this information the easiest. As well I would like to put them into a database so I can make totals and monitor everything. I can program a bit C# so maybe there is a way to use this code.
I would like to know how I get the needed data from the webpages.
I would probably use the AngleSharp project to do the scraping: https://github.com/AngleSharp/AngleSharp

how to Maximize/Minimize separate sections in asp.net web application

I am developing one ASP.NET Web Page in that I Want to show data, as it is in the attached link. So Please go through it.
So I want the similar functionality in my We Page also.
As We can see here I have separate section for Store Details, POS Details, Registered Banks Details and so on. And If I click on +/- symbol, I should be able to maximize and minimize that particular section.
Actually I am very new to Asp.net, I have learned things by myself only so far, Nobody here to guide me.
So I have no idea how to do this?
What to do and what items I need to select from toolbox in Visual Studio.
I have idea about PAnel Control , but with panel control I am not able to get maximize and minimize functionality here.
Please help me out .
Thanks
!(http://imageshack.us/content_round.php?page=done&l=img542/4391/spx1.png)
For this you can use AJAX Toolkit controls (ToolkitScriptManager and CollapsiblePanelExtender). And for that do following steps:
(1)Learn and Download AJAX Toolkit from http://www.asp.net/ajaxlibrary/ajaxcontroltoolkitsamplesite/ or http://www.asp.net/ajaxlibrary/act.ashx or
http://www.stackoverflow.com/questions/15258994/how-to-add-ajaxcontroltoolkit-to-toolbox-in-vs-2012
(2)Add toolkit into your project and create one example with any one control of the toolkit
(3)Try below example as you want
<cc1:ToolkitScriptManager ID="ToolkitScriptManager2" runat="server">
</cc1:ToolkitScriptManager>
<asp:Panel ID="pnlCPTop" runat="server" Width="500">
<table width="100%">
<tr>
<td>
POS DETAILS
</td>
<td align="right" valign="top">
<asp:Label ID="lblTop" runat="server">(Show Details...)</asp:Label>
<asp:ImageButton ID="imgTop" runat="server" AlternateText="(Show Details...)" ImageUrl="App_Themes/Default/images/expand_blue.jpg" />
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel ID="pnlTop" runat="server" Width="500">
<table width="100%">
<tr>
<td>
TID :
</td>
<td>
abc...
</td>
<td>
Name :
</td>
<td>
xyz ...
</td>
</tr>
</table>
</asp:Panel>
<cc1:CollapsiblePanelExtender ID="cpTop" runat="server" TargetControlID="pnlTop"
BehaviorID="cpTop" CollapseControlID="pnlCPTop" Collapsed="False" CollapsedImage="App_Themes/Default/images/expand_blue.jpg"
CollapsedText="(Show Details...)" ExpandControlID="pnlCPTop" ExpandedImage="App_Themes/Default/images/collapse_blue.jpg"
ExpandedText="(Hide Details...)" ImageControlID="imgTop" SuppressPostBack="True"
TextLabelID="lblTop">
</cc1:CollapsiblePanelExtender>
In web config
<system.web>
<pages>
<controls>
<add tagPrefix="cc1" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" />
I hope this may helps you. I suggest to first learn AJAX Toolkit and then add to tool box and then try above code.
Another way is using javascript like below:
javascript
<script type="text/javascript">
function funHide() {
document.getElementById('imgShow').style.display = 'block';
document.getElementById('trPOSDETAILS').style.display = 'none';
document.getElementById('imgHide').style.display = 'none';
}
function funShow() {
document.getElementById('imgShow').style.display = 'none';
document.getElementById('trPOSDETAILS').style.display = 'block';
document.getElementById('imgHide').style.display = 'block';
}
</script>
aspx or html
<table width="500px">
<tr>
<td colspan='3'>
POS DETAILS
</td>
<td align="right">
<img id='imgShow' src='App_Themes/Default/images/expand_blue.jpg' alt='Show Details...' onclick="funShow()" style='display:none;'/>
<img id='imgHide' src='App_Themes/Default/images/collapse_blue.jpg' alt='Hide Details...' onclick="funHide()" />
</td>
</tr>
<tr id="trPOSDETAILS">
<td>TID :</td>
<td>abc...</td>
<td>Name :</td>
<td>xyz ...</td>
</tr>
</table>
Please mark this answer useful if this solve your problem.

How to get the html table value in asp.net mvc?

Here i am a dragging a table(1) row and dropping it in another table(2) using asp.net mvc similar to this one http://www.redips.net/javascript/drag-and-drop-table-row/ and the values are from database .It is working fine and what i need is the html table values (i.e the values inside the td) of the table(2).how can i get those values and save it in dataset in asp.net MVC.Here is my code
<div id="drag">
<table class="tbl1">
<tr>
<th colspan="2">
Table 1
</th>
</tr>
<% foreach (var item1 in Model)
{ %>
<tr class="rl">
<td class="rowhandler">
<div class="drag row">
<%= Html.Encode(item1.Id) %>
</div>
</td>
<td class="rowhandler">
<div class="drag row">
<%= Html.Encode(item1.Title) %>
</div>
</td>
</tr>
<% } %>
<tr style="display: none;">
<td colspan="2">
<span>Message line</span>
</td>
</tr>
</table>
<table id="tab" runat="server">
<tr>
<th colspan="2" class="mark">
Table 2
</th>
</tr>
<tr class="rd">
<td>
</td>
<td>
</td>
</tr>
<tr style="display: none;">
<td colspan="2">
<span>Message line</span>
</td>
</tr>
</table>
</div>
Any suggesion?I am new to MVC
Use jQuery ajax to save the data in server. You can make a call to a controller action from your jquery with your data and it can save the data to your tables.
var mydata=""; /// read your table cells values and store it in this string
$.post("yourcontroller/action/", { data : mydata} ,function(response){
//do something with the response from action
});
As Brian already suggested, traversing the DOM maybe a bad idea. A better way would be to store the table2 data in a javascript array (whenever a drop event occurs add to the array, or remove from the array when cells are dragged off the table). Then have an ajax call to submit the whole array in one go.
If I am understanding this correctly when the page loads you have the data for both tables in the database. You can just keep a working set of the changes being made to the table and update those records accordingly. Add logic to the "drop" event in your JS to store the item's ID and it's new position.
This saves you from having to update unaffected records and also from traversing the entirety of both tables on submit.

Extract region and replace them back for a template

I have a template where I want to replace certain regions. In my example below, I want to extract the regions between the ... comments, manipulate it, then replace them back after the manipulation.
I do not need the logic to merge the fields, but I need to extract the regions so I can use my logic and place it back into the template.
Does anyone know of an elegant or simple way to extract these regions? I am also hoping to extract the url values in the process as well if it is easy to do along the way.
<table width="700" border="0" align="center" cellpadding="4" cellspacing="0">
<tr>
<td align="center" valign="top">
<!--DynamicSlotStart url="http://www.test.com/itemdisplay0_10751_-1_57436_10001"-->
<table>
<tbody>
<tr>
<td><p><a title="[element='title']" href="[url]"><img border="0" alt="[element='title']" src="[element='photo' property='src' maxwidth='135']" width="135" height="135" /></a></p></td>
</tr>
<tr>
<td><span>[element='h1']</span></td>
</tr>
<tr>
<td><span><strong>[element='price']<br />
</strong></span><span>[element='was_price']</span></td>
</tr>
<tr>
<td><span><a title="[element='title']" href="[url]">Details</a></span></td>
</tr>
</tbody>
</table>
<!--DynamicSlotFinish-->
</td>
<td align="center" valign="top">
<!--DynamicSlotStart url="http://www.test.com/itemdisplay0_10751_-1_3379_10001"-->
<table>
<tbody>
<tr>
<td><p><a title="[element='title']" href="[url]"><img border="0" alt="[element='title']" src="[element='photo' property='src' maxwidth='135']" width="135" height="135" /></a></p></td>
</tr>
<tr>
<td><span>[element='h1']</span></td>
</tr>
<tr>
<td><span><strong>[element='price']<br />
</strong></span><span>[element='was_price']</span></td>
</tr>
<tr>
<td><span><a title="[element='title']" href="[url]">Details</a></span></td>
</tr>
</tbody>
</table>
<!--DynamicSlotFinish-->
</td>
<td align="center" valign="top">
<!--DynamicSlotStart url="http://www.test.com/itemdisplay0_10751_-1_104854_10001"-->
<table>
<tbody>
<tr>
<td><p><a title="[element='title']" href="[url]"><img border="0" alt="[element='title']" src="[element='photo' property='src' maxwidth='135']" width="135" height="135" /></a></p></td>
</tr>
<tr>
<td><span>[element='h1']</span></td>
</tr>
<tr>
<td><span><strong>[element='price']<br />
</strong></span><span>[element='was_price']</span></td>
</tr>
<tr>
<td><span><a title="[element='title']" href="[url]">Details</a></span></td>
</tr>
</tbody>
</table>
<!--DynamicSlotFinish-->
</td>
<td align="center" valign="top">
<!--DynamicSlotStart url="http://www.test.com/itemdisplay0_10751_-1_80977_10001"-->
<table>
<tbody>
<tr>
<td><p><a title="[element='title']" href="[url]"><img border="0" alt="[element='title']" src="[element='photo' property='src' maxwidth='135']" width="135" height="135" /></a></p></td>
</tr>
<tr>
<td><span>[element='h1']</span></td>
</tr>
<tr>
<td><span><strong>[element='price']<br />
</strong></span><span>[element='was_price']</span></td>
</tr>
<tr>
<td><span><a title="[element='title']" href="[url]">Details</a></span></td>
</tr>
</tbody>
</table>
<!--DynamicSlotFinish-->
</td>
</tr>
</table>
Maybe this project will be helpful: Html Agility Pack
What is exactly the Html Agility Pack (HAP)?
This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams).
Html Agility Pack now supports Linq to Objects (via a LINQ to Xml Like interface). Check out the new beta to play with this feature
Sample applications:
Page fixing or generation. You can
fix a page the way you want, modify
the DOM, add nodes, copy nodes,
well... you name it.
Web scanners.
You can easily get to img/src or
a/hrefs with a bunch XPATH queries.
Web scrapers. You can easily scrap
any existing web page into an RSS
feed for example, with just an XSLT
file serving as the binding. An
example of this is provided.

Categories