Anyway to find content control in usercontrol using javascript?

I have a master page, content page and a user control.
1. In the user control, i have a button that I call javascript on usercontrol to clear some textfields.

2. In content page, I have a label that I also want to clear when the user-control button is clicked.

Anyway I can access this label in usercontrol, using javascript? this is what I have now.

In user control

<script type="text/javascript">
    function clrCtrl() {
        document.getElementById("<%= search_category_city.ClientID %>").value = "";
    }

 <asp:Button  ID="btnClear" Text="Clear" runat="server" OnClientClick="clrCtrl();return false;"  />

Open in new window


In Content page
<asp:Label runat="server" ID="lblMsgFax" />

Open in new window

LVL 8
CamilliaAsked:
Who is Participating?
 
Obadiah ChristopherCommented:
In the UserControl create a public property like this

public Label PageLabel { get; set; }

Open in new window


In the page load of the page set the value of this property to the label in the content page.

PageLabel = lblMsgFax;

Open in new window


And in the UserControl add the OnClientClick from server side

btnClear.OnClientClick = "javascript:clrCtrl('"+PageLabel.ClientID+"');";

Open in new window


Change the Javascript function to:

function clrCtrl(lblId) {
        var lblObj = document.getElementById(lblId);
        lblObj.innerHTML = "";
        document.getElementById("<%= search_category_city.ClientID %>").value = "";
    }

Open in new window

0
 
CamilliaAuthor Commented:
i'll try today, thanks for responding
0
 
CamilliaAuthor Commented:
I tried this but get a NULL error for the label. I put a debug step and this line is always null

public Literal PageLabel { get; set; }

I put an alert in the javascript and lblObj is null

 var lblObj = document.getElementById(lblId);
        alert(lblObj);
        lblObj.innerHTML = "";

Do I need to change that property somehow to set the value?
0
 
CamilliaAuthor Commented:
the control yeilds as this

<td width="310"><span class="feedback">Please click 'Next' to refer by fax.</span></td>

no ID. I'll dig deeper
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.