473,513 Members | 11,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User Control Question: Button Onclick Event won't work (won't fire)

I have a link (.ascx) and that generates an Add form on that page. The
autopostback dropdown is within a "If Not IsPostBack Then" statement.
The form that is created is all via static html in the user control.
The problem is, no matter what even when no data is filled out in the
form, the submit button just postsback the page and nothing happens. I
have 2 dummy links on the page right now, and the form is automatically
created without a link click for testing purposes. I thought that
onclick events work in a user control but maybe I'm wrong.

Oh, and stuff works in the .ascx, for instance response.write's appear
from the Page_Load, it's just this onclick event that won't work.

Here's the code:
Sub Page_Load(Sender As Object, E As EventArgs)
'Constants, link, local path, and sql connection.
strLink =
System.Configuration.ConfigurationSettings.AppSett ings("LinkPath")
strPath =
System.Configuration.ConfigurationSettings.AppSett ings("SitePath")
Conn = New
SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings("SQLConnect"))
strBaseQuery = "Select TableName from TableGenData where Display = 4
Order By TableName Asc;"

If Not IsPostBack Then
conn.open()
'Populates the dropdown with the Status Names.
cmdSelect = New SqlCommand(strBaseQuery, Conn)
dtrTableData = cmdSelect.ExecuteReader()
TableDropDown.DataSource = dtrTableData
TableDropDown.DataTextField = "TableName"
TableDropDown.DataValueField = "TableName"
TableDropDown.DataBind()
dtrTableData.Close
conn.close()

Dim li As ListItem
li = New ListItem("Select a Table", "0")
TableDropDown.Items.Insert(0, li)
End If

'The control is added here.
ctlControl = LoadControl( "AddDB.ascx" )
plhContent.Controls.Add( ctlControl )
'<ManageDB:AddDB ID="ctlAddDB" Runat="Server" />
End Sub

***********************
Here is the control:

'On button submit, grab the data from each form and submit it to SQL.
Sub SubmitForm_Click(s As Object, e as EventArgs)
Response.write( "omg it worked" )
End Sub

Now, of course there is a form below that has all the .text fields but
I'm hoping you can imagine those being there. The .ascx also contains
the <asp:Button OnClick=SubmitForm_Click runat=server /> as well. If
anything, I tried getting it to just error on me and nothing would
happen. I'm not sure if you would need more info, but if so I have
absolutely no problem providing it.

I looked around groups, and around forums for about an hour but I
couldn't find an answer. Maybe I'm just looking in the wrong places,
with the wrong search terms.

Thanks for the help in advance!

Nov 19 '05 #1
4 3063
Can anyone at least answer this question?

Can onclick events work in user controls? If so, can someone give me a
basic example?

Nov 19 '05 #2
Chad,

Yes, the events will work, but everything has to be in place.
I typically let the IDE sort of generate the button click routine, so
it looks like this:
Private Sub btnOk_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnOk.Click

and then you shouldn't need the "OnClick" in the html. I've seen it
both ways.

Note that the pageload for the containing page will occur before the
event
for the button click. It helps to understand the sequence of events.

One thing to watch for is if you have multiple controls you should
assign them each an id , otherwise things can get confused when
postbacks occur.

Nov 19 '05 #3
Thank you, I figured the events would work... I guess I'm just missing
something.

That does shed some light on the issue.

I have been doing asp.NET development for a while, but I just started
using user controls, so this concept is all a bit foreign to me and
most resources I look at don't tend to cover events in the user
control, but let the even get handled in the page containing the user
control.

Thanks.

Nov 19 '05 #4
I found the problem, and it was just me being stupid.

I had:
Sub SubmitForm_Click(s As Object, e as EventArgs)
If blnIsValid = True Then
Response.write( "omg it worked" )
End If
End Sub

I erased the entry on accident that made the boolean value = true. So,
thanks, and I apologize for making such a ridiculous post. I also can't
believe how long this took me to figure out.

Nov 19 '05 #5

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

Similar topics

7
7715
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control...
1
8135
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the...
5
2054
by: V. Jenks | last post by:
Long story as short as possible: I have a page (aspx) that contains a user control (ascx). In the form the user can enter a username and password. If they do, the password box auto-posts-back...
4
4470
by: Barb | last post by:
I have a user control as my Save button for my page. When the Save button is clicked, I want some client-side validation to take place from a javascript function in the page, and then I'd like the...
6
12261
by: grist2mill | last post by:
I want to create a standard tool bar that appears on all pages that is a control. The toolbar has a button 'New'. What I wolud like when the user clicks on 'New' depends on the page they are on. I...
6
3351
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
6
3916
by: hemant.singh | last post by:
Hi all, I am trying to get a way by which I'll know exactly when user goes out of my site by clicking on close button in browser, So that w/e user click close button in browser, I can send a...
9
3166
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
2
15044
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.