Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 19th, 2006, 06:46 AM
Registered User
 
Join Date: Oct 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to daffodils
Default Much much problem with the User Control!


Hi,
  I'm using ASP.net 1.1 and trying to make a header user control for my page....The user should be able to change the logo in the user control at his will ...

What i did is this:

1. Added a new Web User Control...CmpHd.ascx and added an image control.

2. Added a property and initializing it at page load as follows

Public Class CmpHd
    Inherits System.Web.UI.UserControl
Private _imgUrl As String

    Public Property ImgUrl() As String
        Get
            Return _imgUrl
        End Get
        Set(ByVal value As String)
            _imgUrl = value
        End Set
    End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        shwPic.ImageUrl = _imgUrl.ToString
    End Sub
end Class

3. Then dragging the control CmpHd.ascx from the Solution Explorer onto the TestHeader.aspx page and renaming it as HdControl1.

I'm being able to cahnge the ImageUrl at runtime like this on a button click(I'm using a <INPUT id="fn" type="file" runat="server"> to browse and select an image )

Private Sub bttn_ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttn_ok.Click
        '******this method is working
        Dim UC As UserControl
        Dim imgUC As System.Web.UI.WebControls.Image
        UC = Page.FindControl("HdControl1")
        imgUC = UC.FindControl("shwPic")
        imgUC.ImageUrl = fn.ResolveUrl(fn.Value)
End Sub

But this code is working when I'm converting the shwPic.ImageUrl = _imgUrl.ToString statement to a comment.

When this statement is not commented, it's giving a "Object reference not set to an instance of an object." error.

Also when i'm writing the name of the user control hdcontrol1 and putting a dot after it I'm not getting the custom property I made for the class.

I actually want to set the ImageUrl property of the image control using the custom property I made ......Please help me with this.




There's no defeat untill you stop trying....
 
Old October 19th, 2006, 07:21 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Declare your objects with New.

Dim UC as New UserControl
Dim imgUC as New System.Web.UI.WebControls.Image

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 19th, 2006, 08:36 AM
Registered User
 
Join Date: Oct 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to daffodils
Default

Thanks for your help

Actually "Object reference not set to an instance of an object." error stoped when I declare
Protected WithEvents HdControl1 As CmpHd
(which I thought the .net development tool will do it when I drag the control on the form just like it did for regular server controls.)

now I can access the ImgUrl property like this on the button click
HdControl1.ImgUrl = fn.ResolveUrl(fn.Value)

the code in the page load event of the user control is this

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        shwPic.ImageUrl = _imgUrl.ToString
    End Sub

But it's not working..I mean there's no error shown but the image i'm selecting is not being shown....What to do?


There's no defeat untill you stop trying....
 
Old October 19th, 2006, 09:01 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok hold on.

How do you determine the value of _imgURL in your UC? By default this string will be empty. How exactly are you passing a new URL to the UC? What is fn?

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 19th, 2006, 11:30 PM
Registered User
 
Join Date: Oct 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to daffodils
Default

I'm using a <INPUT id="fn" type="file" runat="server"> to browse and select an image.

So the fn.value or fn.ResolveUrl(fn.Value)gives the full path of the image.

Now I'm using
HdControl1.ImgUrl = fn.ResolveUrl(fn.Value)

the page load of the user control actually contains this:-
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        shwPic.ImageUrl = _imgUrl.ToString
    End Sub
where shwPic is the image control's id.

This method is not working...I mean no error is being reported but the pic is not being shown.

There's no defeat untill you stop trying....
 
Old October 20th, 2006, 07:18 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Well, are you uploading the image to the server? Here is the thing, if say I were to come to your page and use this UC and selected an image to display off of my HD, its not going to display for obvious reasons. The image exists on my machine not your server. Maybe I am misunderstanding you, but that seems to be the problem.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 20th, 2006, 08:22 AM
Registered User
 
Join Date: Oct 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to daffodils
Default

Thanks I got ur point...that means I'v to keep certain number of images in the "Includes" folder in my website and then select one of them from there.......right?

There's no defeat untill you stop trying....
 
Old October 20th, 2006, 10:46 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Yes. The images you are trying to load must reside somewhere on the server you just need a way to provide the user with a list of images they can choose from. hth

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem while using User Control vivekshah ASP.NET 1.0 and 1.1 Professional 0 August 7th, 2008 02:46 AM
Dynamic user control problem sandeep General .NET 0 September 26th, 2005 09:42 AM
User Control Problem alyeng2000 ASP.NET 1.0 and 1.1 Basics 4 March 19th, 2004 11:22 PM
Web User Control Problem shmacgregor VS.NET 2002/2003 18 February 22nd, 2004 06:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.