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.0finding a control in a DNN modulefinding a control in a DNN module
Previous
 
Next
New Post
11/26/2007 10:39 AM
 

I am creating my first dnn module and to make the story short here is the concept I am having trouble with:

When I press a button I want put text in a label.
Here is my procedure to put the messsage into the label:

Sub setMessage(ByVal strMessage As String)
            Dim lblMessage As Label = New Label
            lblMessage = CType(lstContent.FindControl("lblError"), Label)
            lblMessage.Text = strMessage
End Sub

This is my label:
<asp:Label ID="lblMessage" runat="server" Text="" CssClass="c_message"></asp:Label>

on my page there is a datalist named lstContent. the label is within the datalist.
But I have tried to put the label outside the datalist for testing and that also doesn't work.

to find my label I've tried to address the label directly, I've tried page.FindControl(lblMessage) and when the label is in the datalist I've tried the lstContent.FindControl(lblMessage). Also tried Page.Form.FindControl("lblMessage")

Can anyone tell me when what I am doing wrong or what I am missing. Is there another control I have got to adress to retrieve my label?

 

All help is really appreciated. Thanks in advance.

 

 
New Post
11/26/2007 5:13 PM
 
try this (Label & Button)


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click lblMessage.Text = "Hello World" End Sub You do not need to create/find the label. The label is there. You can put the code also in Page_Load
 
New Post
11/26/2007 7:47 PM
 

1. Why is the label in a list control?  Will you potentially load more than one?

2. If it is outside the list, then as jipsen said, it should be available to your code (assuming you declared it in the code behind.)

3. The code you pasted is finding "lblError" but the ID is "lblMessage" ?

 

 
New Post
11/27/2007 4:52 AM
 

I get object reference not set or nullreference exception unhandled.  on the lblMessage.Text = strMessage

1. potentially at a later stage. not at the current time.

2. how should I declare it? dim lblMessage as Label won't make it work. dim lblMessage as Label = new Label won't make it work

3. Sry forgot to change that. I got those matching in my code

I have another asp.net app where this works perfectly (non dotnetnuke).

This is my button:

<asp:Button ID="btnVerzenden" runat="server" Text="Verzenden" OnClick="btnVerzenden_Click" />

This is the onClick event of the button:

Protected Sub btnVerzenden_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim btnVerzenden As Button = sender
            If controleReg() Then
                If controleDeelname() Then
                    verwerkgegevens()
                    btnVerzenden.Text = "Test1"
                    setMessage("Test1b...")
                Else
                    setMessage("Test2...")
                    btnVerzenden.Text = "Test2"
                End If
            Else
                setMessage("Test3")
                btnVerzenden.Text = "Test3..."
            End If
        End Sub

If I add Handles btnVerzenden.Click like jispen suggested it says: Handles clause requires a withevents variable defined in the containing type or one of its base types.

 

 
New Post
11/27/2007 7:44 AM
 

Your declaration should look like this:

Protected WithEvents lblMessage As System.Web.UI.WebControls.Label

And it should be outside of any method.  It is possible a difference in environment could be causing you the problem.  Check the code in the region - #Region " Web Form Designer Generated Code " in the app that works and see if you find the declaration for btnVerzenden.

 

 

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0finding a control in a DNN modulefinding a control in a DNN module


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