Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Manually controlling name attribute of tags for asp.net html controls

Posted on 2007-11-22
4
Medium Priority
?
2,582 Views
Last Modified: 2013-11-29
I'm writing a form to send credit card info to a payment gateway and the API requires me to include a number of hidden fields woth very specific names. So when asp.net prefixes my names with e.g. ctl00$ContentPlaceHolder1 rendering this html tag:

<input type="hidden" name="ctl00$ContentPlaceHolder1$shopid" id="ctl00_ContentPlaceHolder1_PaymentBox1_shopid" value="12xxxxxxxxxx" />    

The form doesn't comply with the API spec and the transaction is rejected.

How do I force ASP.NET not to prefix the name attribute? Or how do I programatically set the value attribute of a plain html tag from my code behind file?

Thanks,
Kaare
0
Comment
Question by:krubak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:gocemi
ID: 20334083
gocemi:
1.you should add this in the code behind:
/// <summary>
/// Override to force simple IDs all around
/// </summary>
public override string ClientID
{
get
{
if(this.Id == "hidden field")
//return changed name for this control only
return "canged_name";
//for others return real client id
else return this.ClientID;
}

4. With this you actually override the Client ID value for a control
5. Be very carefull not to have 2 controls with same id, cos it will throw exception
6. I've tried and it is functioning, actually you can have each control to have same id as the server's one.

with this name will be chaned as well
0
 
LVL 3

Author Comment

by:krubak
ID: 20334988
Could You elaborate a bit? I've tried to put this in my partial class for the page, e.g.

public partial class CheckoutDK : System.Web.UI.Page
{
    public override string ClientID
    {
        get
        {
            if (this.ID == "shopid")
                //return changed name for this control only
                return "shopid";
            //for others return real client id
            else
                return this.ClientID;

        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
       ....
    }
}

I've tried to put a breakpoint on the if (this.ID == "shopid") but it's apparently not called when the page is rendered.
0
 
LVL 5

Accepted Solution

by:
gocemi earned 1500 total points
ID: 20337731
Hi,

One more thing i forgot ( sorry)

Every webUsercontrol that you are using will need to have it's Client and uniqueid Changed.
So  In the web users control, not the PAGE since all controls that are directly in the page will be named OK

public override string ClientID/UNIQUEID
    {
        get
        {
                return "";

        }
    }


So whenever page is rendering ListBox inside WebUserControl that is placed on a page,
PAge will ask the Control to give it's uniqueid that with this code be "", so controls inside will be not prefixed.

0
 
LVL 3

Author Comment

by:krubak
ID: 20340477
Thanks, I got it. I ended up using the overrides described above while creating new server controls for the html controls I needed on the form to control the UniqueID and the name attribute.

If others find this thread these links might be helpfull:
http://www.west-wind.com/WebLog/posts/4605.aspx
http://forums.asp.net/p/1050481/1483968.aspx#1483968
http://msdn2.microsoft.com/EN-US/library/aa310915(vs.71).aspx
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question