473,583 Members | 2,858 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(Sende r As Object, E As EventArgs)
'Constants, link, local path, and sql connection.
strLink =
System.Configur ation.Configura tionSettings.Ap pSettings("Link Path")
strPath =
System.Configur ation.Configura tionSettings.Ap pSettings("Site Path")
Conn = New
SqlConnection(S ystem.Configura tion.Configurat ionSettings.App Settings("SQLCo nnect"))
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(strB aseQuery, Conn)
dtrTableData = cmdSelect.Execu teReader()
TableDropDown.D ataSource = dtrTableData
TableDropDown.D ataTextField = "TableName"
TableDropDown.D ataValueField = "TableName"
TableDropDown.D ataBind()
dtrTableData.Cl ose
conn.close()

Dim li As ListItem
li = New ListItem("Selec t a Table", "0")
TableDropDown.I tems.Insert(0, li)
End If

'The control is added here.
ctlControl = LoadControl( "AddDB.ascx " )
plhContent.Cont rols.Add( ctlControl )
'<ManageDB:AddD B 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_Clic k(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=SubmitF orm_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 3066
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(ByV al sender As Object, ByVal e As
System.EventArg s) 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_Clic k(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
7725
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 which will be used to query sql server to repopulate the datagrid in the user control. I also wrapped the user control in a panel element so I...
1
8144
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 first time the control is dynamically loaded, everything works fine. After that, if the control is loaded again from the page button event handler,...
5
2056
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 and checks to see if the user already exists in the database. If yes, the rest of the form fields on the page are populated with that existing...
4
4475
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 server event to fire to update the database. I've successfully done this with a normal webcontrol via: myControl.Attributes("onclick") =...
6
12269
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 would like to do this by defining a NewFunc() that is different in each (code-behind) page which is called by the standard 'New' button in the...
6
3359
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 the usual stuff of recreating the usercontrol in the Page Init event. The 'failure' sequence is as follows: - select web form button to display...
6
3930
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 signal to server. This seems to be achievable with body unload events, but it is little too much, as even if user navigate within my site, this event...
9
3176
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 load with different data (locations, departments, etc.).
2
15057
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 been able to find the cause of the problem, and will describe it here first textually and then through a code example. The purpose of what I am...
0
7888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7811
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
6571
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5689
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3811
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2317
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 we have to send another system
1
1416
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1147
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.