Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Add control using code behind get different IDAdd control using code behind get different ID
Previous
 
Next
New Post
3/16/2008 5:30 PM
 

I add a control in code behind:

 

 

HtmlTableCell cell = new HtmlTableCell();
DNNTextSuggest textSuggest = new DNNTextSuggest();
textSuggest.ID = textPrefix + question.id;
cell.Controls.Add( textSuggest );

But i have a problem when i bulid website and check the output

In Admin / Edit mode

 <input name="dnn$ctr450$ViewRegister$TEXT_4" type="text" maxlength="100"
        id="dnn_ctr450_ViewRegister_TEXT_4" class="formbox_default" questionid="4" sysimgpath="images/"
        tscss="SuggestTextMenu GroupSuggestMenu" csshover="SuggestNodeOver" del=" "
        postback="__doPostBack('dnn$ctr450$ViewRegister$TEXT_4','[TEXT]Click')"
        callback="dnn.xmlhttp.doCallBack('TEXT_4 dnn_ctr450_ViewRegister_TEXT_4',this.getText(),this.callBackSuccess,this,this.callBackFail,this.callBackStatus,null,null,0);" />

But in view mode

<input name="dnn$ctr450$ViewRegister$ViewRegister$TEXT_4" type="text" maxlength="100"
        id="dnn_ctr450_ViewRegister_ViewRegister_TEXT_4" class="formbox_default" questionid="4" sysimgpath="images/"
        tscss="SuggestTextMenu GroupSuggestMenu" csshover="SuggestNodeOver" del=" "
        postback="__doPostBack('dnn$ctr450$ViewRegister$ViewRegister$TEXT_4','[TEXT]Click')"
        callback="dnn.xmlhttp.doCallBack('TEXT_4 dnn_ctr450_ViewRegister_ViewRegister_TEXT_4',this.getText(),this.callBackSuccess,this,this.callBackFail,this.callBackStatus,null,null,0);" />

I want to know why the control ID is different? And how can i aviod it?

Thanks! 

 
New Post
3/16/2008 7:34 PM
 

the names are different as server controls inherit the name of any containers that expose naming containersi.e. panels etc. I recommend that you do not use the id property as it does not change based on naming container. it is better to use clientID, unless you are targetting multiple items within a container i.e.

From the microsoft documentation:


UniqueID

For example, if you include an ASP.NET Label Web server control in a Repeater server control, and assign the Label control an ID property value of MyLabel, and the Repeater an ID of MyRepeater. If you bind data to the Repeater to an ArrayList object with three entries, the resulting UniqueID properties for each instance of the Label server controls are MyRepeater:ctl0:MyLabel, MyRepeater:Ctl1:MyLabel, and MyRepeater:Ctl2:MyLabel.


Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Add control using code behind get different IDAdd control using code behind get different ID


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out