473,385 Members | 1,311 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dynamic UC problems

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
Jun 27 '08 #1
1 1295
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" <da*****************@revilloc.REMOVETHIS.comwrot e in message
news:O%****************@TK2MSFTNGP05.phx.gbl...
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

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Roel Wuyts | last post by:
CALL FOR CONTRIBUTIONS International Workshop on Revival of Dynamic Languages http://pico.vub.ac.be/~wdmeuter/RDL04/index.html (at OOPSLA2004, Vancouver, British Columbia, Canada, October...
5
by: meyousikmann | last post by:
I am having a little trouble with dynamic memory allocation. I am trying to read a text file and put the contents into a dynamic array. I know I can use vectors to make this easier, but it has to...
6
by: MikeY | last post by:
Hi Everyone, Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form. I am looking for a sample that uses a class library...
8
by: George Meng | last post by:
I got a tough question: The backgroud for this question is: I want to design an application works like a engine. After release, we can still customize a form by adding a button, and source code...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
3
by: HP | last post by:
Hi there The problem of dynamically created controls vs viewstate is widely known one. To access values of controls they have to be recreated on Page_Load. Unfortunately it causes many...
3
blackstormdragon
by: blackstormdragon | last post by:
It seems pointers and dynamic arrays are giving me a hard time. Heres part of the assignment. We have to create a class named Student that has three member variables. One of the variables is called...
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
5
by: Hans Kesting | last post by:
Hi, Is there good information about the asp.net page lifecycle in combination with dynamically loaded controls? Or on "how to build dynamic controls"? I keep hitting problems where values are...
5
by: bearophileHUGS | last post by:
I often use Python to write small programs, in the range of 50-500 lines of code. For example to process some bioinformatics data, perform some data munging, to apply a randomized optimization...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.