Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2007-11-22
4
Medium Priority
?
2,583 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
  • 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Businesses who process credit card payments have to adhere to PCI Compliance standards. Here’s why that’s important.
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:
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

916 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