Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dynamic UC problems

Reply
Thread Tools

Dynamic UC problems

 
 
David
Guest
Posts: n/a
 
      06-18-2008
Hi,

Further to my earlier post about using dynamic usercontrols (which I have
still yet to solve), I have another problem.


I am creating the UC in the page by LoadControl. The page itself has a
submit button that is inside an AJAX UpdatePanel.

When I submit the page, the contents of the text boxes of the UC don't
appear to be there.


I have made a public sub in my UC. I pass an ID to the sub. This happens
when the submit button on the page is clicked and it works fine (to this
point).

sort of like this...

Page.
button1_click
begin
TravelUC.SaveTravel(ID)
end


UC
public sub SaveTravel(ID as integer)
begin
code to save the details.
end

However, when I am in the SaveTravel sub routine, the values of my text
boxes (or drop down box) are seemingly empty. Why would this be? Any ideas
on how I can fix it?

Thanks.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


 
Reply With Quote
 
 
 
 
David
Guest
Posts: n/a
 
      06-19-2008
Found the problem...

Here is my code...

(my Page)
Partial Class _Default Inherits System.Web.UI.Page

Dim TravelUC = LoadControl(ResolveUrl("~/UserControls/travel.ascx"))

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

If Not IsPostBack Then

LeftPanel.Controls.AddAt(LeftPanel.Controls.IndexO f(Panel5),
TravelUC)

End If

End Sub



Protected Sub SaveButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs)

Dim AttendeeID as integer = 1

TravelUC.SaveTravel(AttendeeID)

End Sub



(My UC)

Public Sub SaveTravel(ByVal RegistrationID As Integer)

Dim conn As New SqlConnection(connStr)

Dim cmd As New SqlCommand("usp_AttendeeTravel")

cmd.Parameters.Add("@RegID", SqlDbType.Int).Value = RegistrationID

cmd.Parameters.Add("@TravelBy", SqlDbType.VarChar).Value =
TravelDDL.SelectedValue

cmd.Parameters.Add("@PassportName", SqlDbType.VarChar).Value =
PassportName.Text

cmd.Parameters.Add("@HomeAddress1", SqlDbType.VarChar).Value =
HomeAddress.Text

cmd.Parameters.Add("@HomeAddress2", SqlDbType.VarChar).Value =
HomeAddress2.Text

cmd.Parameters.Add("@HomeAddress3", SqlDbType.VarChar).Value =
HomeAddress3.Text

Try

conn.Open()

funcDB.ExecNonQuery(cmd)

cmd.Dispose()

Catch ex As Exception

Finally

conn.Close()

End Try

End Sub


What I didn't know is that the ajax call runs the page load on EVERY ajax
call. As my TravelUC was inside a Not IsPostBack, it wasn't being
re-loaded, even though it remained on the page (due to ajax not refreshing
the whole page).

Moved it outside of the Not IsPostBack and it works.


Still got my other prob though...

I want to be able to dynamically load any user control without knowing
beforehand (as in the above code) what the UC is. i.e. I can have a list of
user controls but I only want to load whichever specific control by
attributes known to the page. I don't want to LoadControl all the controls
on the offchance that I might use it.

The problem as you can see is that my LoadControl happens outside of any
function so that the UC is available to any other functions. I would have
put the loadcontrol inside the pageload, but then I can't call upon any UC
functions from elsewhere in my page.

Any ideas?


Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


"David" <(E-Mail Removed)> wrote in message
news:O%(E-Mail Removed)...
> Hi,
>
> Further to my earlier post about using dynamic usercontrols (which I have
> still yet to solve), I have another problem.
>
>
> I am creating the UC in the page by LoadControl. The page itself has a
> submit button that is inside an AJAX UpdatePanel.
>
> When I submit the page, the contents of the text boxes of the UC don't
> appear to be there.
>
>
> I have made a public sub in my UC. I pass an ID to the sub. This happens
> when the submit button on the page is clicked and it works fine (to this
> point).
>
> sort of like this...
>
> Page.
> button1_click
> begin
> TravelUC.SaveTravel(ID)
> end
>
>
> UC
> public sub SaveTravel(ID as integer)
> begin
> code to save the details.
> end
>
> However, when I am in the SaveTravel sub routine, the values of my text
> boxes (or drop down box) are seemingly empty. Why would this be? Any ideas
> on how I can fix it?
>
> Thanks.
>
> Best regards,
> Dave Colliver.
> http://www.AshfieldFOCUS.com
> ~~
> http://www.FOCUSPortals.com - Local franchises available
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Variables? OR Dynamic Controls =?Utf-8?B?VGVyb3M=?= ASP .Net 1 08-10-2004 01:13 PM
Dynamic control on aspx page, dynamic location Chris Thunell ASP .Net 3 07-21-2004 04:52 PM
VPN between 2 Cisco routers (1 static, 1 dynamic) with access from stat --> dynamic over ISDN Hans-Peter Walter Cisco 3 01-21-2004 02:12 PM
Does Pix or cisco router support dynamic-to-dynamic IPSec VPN? c Cisco 2 01-13-2004 01:53 AM
Re: Dynamic Table with Dynamic LinkButtons Rick Glos ASP .Net 0 07-08-2003 01:09 PM



Advertisments