Don't change the name of my control

P

Peter Morris

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
AutoEventWireup="True" CodeBehind="Modify.aspx.cs"
Inherits="MyWebsite.Views.CollateralTypeAdmin.Modify" Title="Untitled Page"
%>
<asp:Content ID="Content" ContentPlaceHolderID="MainContentPlaceHolder"
runat="server">
<h2>Modify collateral type</h2>
<form action="/CollateralTypeAdmin/Update/<%= ViewData["ID"] %>"
method="post">
Name : <input name="Name" maxlength="64" value="<%= ViewData["Name"] %>"
/><br />
License generator :<select id="LicenseGeneratorSelector"
name="LicenseGenerator" runat="server"/><br />
<button type="submit">Save</button>
</form>
</asp:Content>

In the above example I have a <select> with runat=server. I want the name
to remain as "LicenseGenerator" but it is rendered like so

<select name="ctl00$MainContentPlaceHolder$LicenseGeneratorSelector"
id="ctl00_MainContentPlaceHolder_LicenseGeneratorSelector">

As I am now using viewstate etc and want full control over my html how do I
stop ASPX from renaming my control?


Thanks

Pete
 
M

Mark Rae [MVP]

In the above example I have a <select> with runat=server. I want the name
to remain as "LicenseGenerator" but it is rendered like so

<select name="ctl00$MainContentPlaceHolder$LicenseGeneratorSelector"
id="ctl00_MainContentPlaceHolder_LicenseGeneratorSelector">

Yes, that's standard behaviour for the naming of controls in containers so
as to avoid name conflicts...
As I am now using viewstate etc and want full control over my html how do
I stop ASPX from renaming my control?

You have no need to do this - what are you trying to achieve...?
 
P

Peter Morris

You have no need to do this - what are you trying to achieve...?

I am using ASPX views in the .NET 3.5 web extensions. If the control is not
named "LicenseGenerator" then the LicenseGenerator parameter on my action is
null

[ControllerAction]
public void Update(int id, string name, string licenseGenerator)
{
}

I can't name the parameter
ctl00$MainContentPlaceHolder$LicenseGeneratorSelector, and if I could I
would choose not to :)


Pete
 
M

Mark Rae [MVP]

You have no need to do this - what are you trying to achieve...?

I am using ASPX views in the .NET 3.5 web extensions. If the control is
not named "LicenseGenerator" then the LicenseGenerator parameter on my
action is null

[ControllerAction]
public void Update(int id, string name, string licenseGenerator)
{
}

I can't name the parameter
ctl00$MainContentPlaceHolder$LicenseGeneratorSelector, and if I could I
would choose not to :)

Ah - I see what you mean...

This is mentioned here: http://blog.benhall.me.uk/2007_12_01_archive.html,
with a possible solution...
 
P

Peter Morris

I decided to ditch the control. Instead I downloaded the MVC ToolKit and
did this


<%= Html.Select("LicenseGenerator", ViewData["LicenseGeneratorList"],
ViewData["LicenseGenerator"]) %>

It generates the html, selects the selected value, etc. Job done :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top