How can I trace a placeholder to find its controller? - asp.net

I'm trying to clean up a registration form. The precursors made it easy to adjust most sections of this form, but when I get to the Address portion of the template I uncovered this strange artifact:
<table>
<tr>
<td>
<asp:PlaceHolder ID="phAddress" runat="server"></asp:PlaceHolder>
</td>
</tr>
</table>
The directory system for this site is extensive but I've had luck tracking stuff using text searches of file content. However, with this one searching for "phAddress" gets me nowhere.
=================================================
=================================================

Press CTRL + SHIFT + F and search for the text phAddress with the option selected as "Entire Solution".
As its "PlaceHolder" there is a possibility that "dynamic controls" are added from the "codebehind(aspx.cs or aspx.vb)" page.

Without seeing more of your code base, it's almost impossible to figure out what's being done. Typically, a PlaceHolder is just that - a placeholder for controls that are going to be generated dynamically server-side. Try doing a Ctrl+F for "phAddress" in the codebehind file. If you don't know what that is, take a look at the very top of the asp file, you should see something like this:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="mypage.aspx.cs" Inherits="myprogject.mypage" %>
CodeBehind is the class name, and Inherits= is the directory path of where it lives.
In VS 2010, here's what you're looking for:
This is a C# file, but the structure for VB should be same.

Related

Asp.NET code render block formatting adds whitespaces inside data-bind property

I am using knockout.js with Asp.NET and visual studio (2012 but I get the same problem with 2010 and 2013). My code looks something like this :
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs" Inherits="Solution.ascx.Test" %>
<div>
<span data-bind="value: '<%= String.Empty%>'"></span>
</div>
Every time I paste this code or press ctrl+k, ctrl+d (format file), i get those weird spaces after the code render block. (replaced as XXXX in the following snippet for visibility)
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs" Inherits="Solution.ascx.Test" %>
<div>
<span data-bind="value: '<%= String.Empty%>XXXX'"></span>
</div>
Problem only occurs when using the "data-bind" tag.
I tried disabling "indent contents" in client Options > Text Editor > HTML > Formatting > Tag Specific Options > HTML tag > span with no luck. Does anyone have a solution for this ? Not only is it very annoying but knockout is also parsing those spaces and throwing exceptions.
It's not a problem with the formatting of the text editor, it's a problem with the -bind attribute. For whatever reason, VS does not like this. I've scoured the internet since reading this question, and cannot find any good reason.
I did find, which may be your best method, someone had the exact problem using MVC: using #data-bind in ASP.NET MVC htmlAttributes throws exception
simply use JQuery to change data_bind to data-bind on the fly (as described in the post) and you should be good to go.

Updating a DLL in an aspx

I am an old ASP programmer that recently took a job that has ASP.NET. I have an aspx file that has this at the top:
<%# Page Title="" Language="C#" MasterPageFile="~/Default.Master" AutoEventWireup="true"
CodeBehind="List.aspx.cs" Inherits="itnola.List" %>
And the area that I'm most interested in is this line of code:
<asp:DropDownList ID="dplDistrict" runat="server" Width="205" DataValueField="districtID"
DataTextField="districtname">
There is a table in the database called districts that if I make a modification to that table it displays the changes in this dropdown. However, there is an extra entry in the drop down I assume they have hardcoded.
Not being familiar with ASP.NET, I've looked for a List.aspx.cs file and do not find it anywhere on the server. I did find an itnola.dll file in a bin folder I suspect may have something to do with this. If I remember correctly from my Visual Basic days this dll file is "compiled" and therefore not editable correct? How do I remove this one line in the drop down?

<script> tags inside an <asp:repeater>

I'm outputting a few lines of Javascript within a Repeater control on an ASPX page. I want to use a value from my DataSource inside the script tag.
A very basic example might be:
<asp:Repeater ID="RepeaterBlah" runat="server">
<ItemTemplate>
Hello <%# DataBinder.Eval(Container.DataItem, "SomeName")%>
<script>myfunction(<%# DataBinder.Eval(Container.DataItem, "SomeNumber")%>)</script>
</ItemTemplate>
</asp:Repeater>
I'm aware that most people won't repeat script tags like this, but I am using a small snippet of code from a third-party that you can place anywhere on a page to create a Flash object. You pass it a number so it knows which image gallery to display. No problems using several on one page.
To begin with, this worked fine, although I noticed the colours in Visual Web Developer indicated that it didn't really like the <%# being used inside a <script> tag. Intellisense was going a bit nuts in the code-behind too!
So what is the correct way to pass Dataset items into a script tag?
This perhaps? (Can't quite remember if the + signs should in fact be & signs though)
<%# "<script>myfunction(" + DataBinder.Eval(Container.DataItem, "SomeNumber") + ")</script>" %>
Another alternative syntax would be the following:
<%# Eval("SomeNumber", "<script>myfunction({0});</script>") %>
This uses the optional parameter where you can supply a format string.

what is the meaning of this?

I know that this will sound stupid to some of you, but when an ASPX page has something like this:
<%# Page Title="[$TITLES_listevents{uneditable}]" Language="C#" MasterPageFile="~/sitebase/templates/page.master" AutoEventWireup="true" CodeBehind="list.aspx.cs" Inherits="list" %>`
or something like:
<div id="panelGroupEventPackageOnlyDescription" runat="server" visible="<%# ShowGroupEventPackageOnly %>">
[$ITEMLIST_groupeventpackageonly]
</div>
what does it mean?
Regards
I'm assuming that your query is for the bits that look like this: Title="[$TITLES_listevents{uneditable}]"
It doesn't look like asp.net to me. It could be that the page was generated by a templating tool that left some rubbish behind, is it in source control, can you ask whoever created the page?
Hey All,
apparently it means that It will use site text to set the title, this is done when there is an xml file that produces site data and you need some of those data to be published dynamically to you front end website. this is the results of custom controls being used on things like label, dropdownbox etc...
this is one of the legacy piece of software where the one who wrote the code is gone AWOL with little doc, only happens when you are emerging from recession lol.....

asp.net - Use ascx as a layout template

This is my layout template (ascx without code behind)
<%# Control Language="C#" AutoEventWireup="true" Inherits="ws.helpers.LayoutUC" %>
<div>blah blah blah</div>
<ws:Panel runat="server" ID="left"></ws:Panel>
<ws:Panel runat="server" ID="main"></ws:Panel>
<ws:Panel runat="server" ID="right"></ws:Panel>
Modules will be added into ws:Panel later.
I also allow my user create their own ascx file to custom their page layout. And because of this i do a string replace all dangerous part like script tag (runat="server"), all asp.net html tag, <%, <%#, <#.... from their custom.
Im not worry about XSS, so dont comment on it, and ask why?
I want know your thinking about this. Is is safe? Is it scalable? Is it standard or a bad way?
Have a look at the INaminingContainer Interface http://msdn.microsoft.com/en-us/library/system.web.ui.inamingcontainer.aspx.
<asp:YourControl>
<LeftColumn>
<asp:Literal ID="literal1" runat="server" Text="User created literal" />
</LeftColumn>
</asp:YourControl>
In the .ascx from the users, they register your control and insert asp.net code into properties. In the 'YourControl' class you create placeholders and insert the markup set to a specific property into these placeholders. (e.g. everything between <LeftColumn> and </LeftColumn> will the inserted into
<asp:Placeholder ID="PlaceholderLeftColumn" runat="server"/>
Edit: I summed some of the TemplateContainer issue up and posted it here: http://www.tomot.de/en-us/article/2/asp.net/how-to-create-an-asp.net-control-that-behaves-as-a-template-container-to-nest-content-via-markup
You are allowing user-uploaded content; this is inherently unsafe and there are whole books dedicated to best practices. Given that you are doing it anyway, as long as you make sure you scrub the input, is it scalable? You are allowing creation of user-uploaded files on your site. How many will there be? How many users? What about load-balancing? This solution will not scale for many users, files, or servers.
It sounds like you are trying to create a simple CMS. Why not use one that exists currently, or adopt parts of an open source solution?

Resources