clientid

  • Thread starter Abraham Andres Luna
  • Start date
A

Abraham Andres Luna

i have a control on a content page
which protected method of the control should i use to get the clientid?

ex: ctl00_cphMainContent_tbCusId

i started with OnInit but it only returned "tbCusId"

thank you for your help. if you need me to show my code let me know
 
P

Phillip Williams

It does not matter which method (the handler of OnInit, load, or other
events). You only need retrieve the UniqueID (not the ID) property of your
control ***after*** it has been databound. You would not want to retrieve a
UniqueID of a control before it is created.
 
A

Abraham Andres Luna

how do i know it has been databound?

this is the master page code (FileName: BasePage.master):
<%@ Master Language="C#" %>
<html>
<head>
<title>CRM - RDK Truck Sales & Service</title>
<link href="/rdk.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript" src="/rdk.js"></script>
</head>
<body>
<form runat="server">
<asp:contentplaceholder id="cphMainContent" runat="server">Content
Here</asp:contentplaceholder>
</form>
</body>
</html>

this is the code for the content page:
<%@ Page MasterPageFile="BasePage.master" %>
<asp:content id="contentMainSection" contentplaceholderid="cphMainContent"
runat="server">
<RDK:CustomerTextBox ID="tbCustomer" runat="server" />
<RDK:RDK_BaseButton ID="btnPost" runat="server" Text="Post"
OnClick="btnPost_Click" />
</asp:content>


this is the code for the CustomerTextBox:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RDK.WebControls
{
public class CustomerTextBox : Control
{
public CusIdTextBox tbCusId;
{
base.OnLoad(E);
//Create Controls
tbCusId = new CusIdTextBox();
//Setup Controls
tbCusId.ID = "tbCusId";
tbCusId.Attributes["onKeyUp"] = "return RDK_TextBox_KeyUp(strCOCUSSQL,
'CusId', strCOCUSDisplay, '" + tbCusId.UniqueID + "', 'divOfCusIds');";
tbCusId.Attributes["onBlur"] =
"javascript:setTimeout(&quot;RDK_HideDiv(divOfCusIds)&quot;, 3000);";
tbCusId.Attributes["autocomplete"] = "off";
this.Controls.Add(tbCusId);
}
}
}

this is the generated html page:
<html>
<head>
<title>CRM - RDK Truck Sales & Service</title>
<link href="/rdk.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript" src="/rdk.js"></script>
</head>
<body>
<form method="post" action="custb.aspx" id="aspnetForm">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwULLTEwMDQ5MzY5MDJkZHsfv8m3MVcbBlHserE0UsGazcNH" />
</div>
<input name="ctl00$cphMainContent$tbCusId" type="text" maxlength="5"
size="6" id="ctl00_cphMainContent_tbCusId" onKeyUp="return
RDK_TextBox_KeyUp(strCOCUSSQL, 'CusId', strCOCUSDisplay, 'tbCusId',
'divOfCusIds');"
onBlur="javascript:setTimeout(&amp;quot;RDK_HideDiv(divOfCusIds)&amp;quot;,
3000);" autocomplete="off" />
</form>
</body>
</html>


see how it just spits out tbCusId instead of ctl00_cphMainContent_tbCusId

thank you for your help
 
A

Abraham Andres Luna

found the answer, i had to add the controls before accessing the uniqueid
like this

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RDK.WebControls
{
public class CustomerTextBox : Control
{
public CusIdTextBox tbCusId;
protected override void OnInit(EventArgs E)
{
base.OnInit(E);
//Create Controls
tbCusId = new CusIdTextBox();
//Add Controls
this.Controls.Add(tbCusId);
//Setup Controls
tbCusId.ID = "tbCusId";
tbCusId.Attributes["onKeyUp"] = "return RDK_TextBox_KeyUp(strCOCUSSQL,
'CusId', strCOCUSDisplay, '" + tbCusId.UniqueID + "', 'divOfCusIds');";
tbCusId.Attributes["onBlur"] =
"javascript:setTimeout(&quot;RDK_HideDiv(divOfCusIds)&quot;, 3000);";
tbCusId.Attributes["autocomplete"] = "off";
}
}
}
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top