Why isn't the ClientIDMode being honored here? - asp.net

I have an ASP.NET 2.0 web application, and on one of the pages I have a div defined like this:
<asp:Panel runat="server" ID="pnlAddJobCode" Visible="false" ClientIDMode="Static">
and it's inside of a content placeholder defined like this:
<asp:Content ID="Content3" ContentPlaceHolderID="MainBodyContent" runat="server">
but when the HTML is generated I get a name like this ctl00_MainBodyContent_pnlAddJobCode so clearly it's not honoring the ClientIDMode. The problem is I need to set some styles on this specific div -how can I get the ClientIDMode to work here?
Does ClientIDMode not work in ASP.NET 2.0? I have found a few articles on Google that elude to it not working, but nothing concrete.

Client ID Mode is new in ASP.NET 4.0. There's more information about it in the breaking changes for ASP.NET v4.0.

Related

Pass variable used in aspx page to user control

We are in ASP.Net Webforms. I come from a LAMP Stack mindset...
ASPX Code (part of it)
<asp:Content runat="server" ContentPlaceHolderID="PH_MainContent">
<h3 class="fleft">
<asp:Literal runat="server" ID="li_title" />
...
<Example:userControl runat="server" someVariable="text" otherVariable=<%=li_title.Text%> thirdVariable=<%=Items["sort"].toString()%> />
So, li_title is a literal set in the code behind, I want to reuse it later, passing it to a userControl, where it shall be displayed in a javascript. Items is page.Items. I have also tried this.li_title (which is suggested to me in Visual Studio 2015).
After reading "quite a few" very similar questions, this seem the solution. However obviously I'm missing the point. What would that be..?
You can create a public property for each variable on your user control and set them in aspx. See this for more information

Can't reference controls in code behind. Visual Studio 2012

There are quite a few questions out there regarding this (for me, recurring) issue, but none of them have solved my problem.
Problem:
Whatever control I add in my aspx page, it is not recognised in the codebehind. Compiling doesn't work, because the ID is not recognised.
None of the following worked:
Clean and rebuild solution.
Close and open VS
Delete asp.net temp files
Check project's target framework.
Check assemblies are all there.
Check designer viewn to see if the control is actually there (it is)
Get control's ID with JS function to check it is the intended one (it is)
The problem has started only recently. In fact, I can reference the older controls fine.
The problem is observed both with standard ASP controls and Telerik ones.
Does anyone know of something else I should try? Please help me, I'm in the middle of a project and this is causing unnecessary delays, ta.
Make sure all of your asp.net controls (in the .aspx file) have the:
runat='server'
tag... Without this, you will not be able to reference the controls.
e.g.
<asp:Label runat='server' Text='Test Label' ID='TestLabel' />
Hope this helped...
Rodit
This is how I solved my issue. For a full account of it, please refer to the comments above.
I've noticed that although my project was already of web application type, designer files weren't showing.
I've forced the designer files to be recompiled by clicking on the ''convert to web application' option
I was then able to reference the control ID.
Thanks to the commentators anyway.
I was having a similar issue, due to the fact that I was using the pre-generated Login page. My solution was to change this section from this:
<asp:Login runat="server" ViewStateMode="Disabled" RenderOuterTable="false">
<LayoutTemplate>
To this:
<asp:Login ID="asplogin" runat="server" ViewStateMode="Disabled" RenderOuterTable="false">
<LayoutTemplate>
basically, I just added an ID to the asp:Login which allowed me to access the objects in the code from behind by prefixing the control name with asplogin
asplogin.youControlNameHere

ASP.NET 3.5 ClientIDs refined

I've created a simple ASP.NET 4.0 application to see how rendered client ids will vary if I change controlRenderingCompatibilityVersion in web.config and ClientIDMode attribute of the control.
Now I've set <pages controlRenderingCompatibilityVersion="3.5"/> and <asp:Label runat="server" ID="Message" ClientIDMode="AutoID" /> and expect to find in the generated markup asp.net-3.5-style ClientID (something like id='ctl00_Message'),
but I see this <span id="Message">Hello world!</span>.
Why does not ASP.NET render it as a 3.5-style id?
If the span is on it's own, then there is no reason to change the ID.
It depends if the control is inside another control. If the span above is inside a Repeater, DataList etc, then the Id will change.

Write code inside ASPxMemo aspx

i have this aspx code that used to work (on .net 2.0):
<Templates>
<EditForm>
<div>
<dxe:ASPxMemo runat="server" ID="Memo1" Text='<%#Bind("field1")%>' Width="100%" Height="60px" ReadOnly="true" BackColor="#E6E6E6"></dxe:ASPxMemo>
...
Now i'm trying to re-use it in the same context but using .net 3.5, but i got an error. I'll try to translate it:
Can't edit Controls because the control contains blocks of code (like
<% ... %>).
so i tried to do via vb.net code this:
Memo1.Text = #Bind("field1")
but looks like a can't access Memo1 because of protection level
how i can make this work again?
edit: found a tutorial here http://demos.devexpress.com/aspxgridviewdemos/GridEditing/EditFormTemplate.aspx
but the tutorial uses bracket insde Text too!
Solved!
Looks like that ASPxGridView doesn't like <% ... %> code inside the page header.
Some days ago i added in my master page's <head> a simple <% Response.Write() %> and the entire ASPxGridView failed because of that.
Moving that code outside the header resulted in a working ASPxGridView, that was not a problem of .NET framework version!

What is the best way to include content within an AJAX TabContainer?

I didn't want to have a ton of code on one page, but to keep the code modular and simple. So in my TabContainer I have the following where each tab refers to a web page and my code is inside each web page. My TabContainer itself is inside the default.aspx page.
<asp:TabContainer ID="tabTOL" runat="server" ActiveTabIndex="0" CssClass="tol">
<asp:TabPanel ID="tabHome" runat="server" TabIndex="0" HeaderText="Home">
<ContentTemplate>
<iframe src="Home.aspx"></iframe>
</ContentTemplate>
</asp:TabPanel>
...
Of course, the problem is that I cannot refer to other tabs or the TabContainer/default page from within any tab. I'm trying to update a TextBox on the default.aspx page from a tab, but there is no reference to it.
Should I bite the bullet and have one huge web page with all the html and code behind? There are a dozen tabs in my TabContainer. I would think this would slow down processing as well. Or, is there a cleaner way to do this and still retain the ability to reference controls on the main page or other tabs?
I'm working in VS2008 and .Net 3.5 and AJAX 3.5.
Thanks!!
Larry
I would suggest that you change the structure of Home.Aspx into a Web User Control (*.ascx). The advantage is that you are now running within the context of the parent page. Therefore all it's functionality is within reach. For example, to acces a textbox on the parent page, from the Home.Ascx, you would do this:
((Default)this.Parent).txtMyTextBox.Text = "Hello";

Resources