|
-
Aug 30th, 2006, 03:26 AM
#1
Thread Starter
Addicted Member
[2005] Regarding user control in asp.net 2005
Hello all,
i am having buttons in my user control,i want that button controls event in my actual page is it possible to get the user control button event in my page .How this can be done.
Kindly help me to solve this.
Thanks in advance
-
Aug 30th, 2006, 11:41 AM
#2
Re: [2005] Regarding user control in asp.net 2005
In your web user control, declare your event.
Code:
public event EventHandler MyButtonClick;
In the button click event inside your web user control,
Code:
protected void Button4_Click(EventArgs e)
{
if(MyButtonClick != null)
{
MyButtonClick(this, e);
}
}
Now, this should be visible and available to the page that contains the web user control. It can handle the web user control's click event.
-
Aug 30th, 2006, 10:00 PM
#3
Thread Starter
Addicted Member
Re: [2005] Regarding user control in asp.net 2005
public event EventHandler MyButtonClick;
This declaration itself is giving an error end of the statement required.I am using vb language .
public event EventHandler MyButtonClick , this is also giving error
Last edited by jnaneswari; Aug 30th, 2006 at 10:42 PM.
-
Aug 30th, 2006, 11:30 PM
#4
Thread Starter
Addicted Member
Re: [2005] Regarding user control in asp.net 2005
I came to know how to declare the event handler in user control using vb language
Public event StandardButton as EventHandler
in my user control i am having add edit save and update buttons.
StandardButton i am giving generalised name.
What i need to give ?the button name itself.
if i gave that button name itself means it is giving an error it is alreadly declared why because i already used that button click event in the user control.What to do
Please help me
-
Aug 31st, 2006, 10:05 AM
#5
Re: [2005] Regarding user control in asp.net 2005
In the web user control, just double click on the button and let its event show up in the codebehind. I used Button4_Click as an example, yours may be different.
-
Aug 31st, 2006, 10:05 PM
#6
Thread Starter
Addicted Member
Re: [2005] Regarding user control in asp.net 2005
Click event of the button is not coming when double click on the usercontrol
button.
my web user control name is StandardButton
double click on the usercontrol button
StandardButton_Load event is coming
Please help me to solve .
Thanks for the reply
-
Sep 1st, 2006, 05:04 AM
#7
Re: [2005] Regarding user control in asp.net 2005
Then you've set something up wrong. It should bring up the click event.
Try adding the event manually to your ascx codebehind:
VB Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
-
Sep 1st, 2006, 05:36 AM
#8
Thread Starter
Addicted Member
Re: [2005] Regarding user control in asp.net 2005
I tried this but it is giving error
Button1 is not a member of this page
-
Sep 1st, 2006, 05:51 AM
#9
Re: [2005] Regarding user control in asp.net 2005
What is the name of your button? Does it have a declaration at the class level? Something like... Protected Button1 As Button?
-
Sep 2nd, 2006, 01:16 AM
#10
Thread Starter
Addicted Member
Re: [2005] Regarding user control in asp.net 2005
i declared protected withevents button1 as webcontrols.button in the class level, after that i write that button1 event handler and i write some code within that, it is not giving any error but in runtime click on button1 click event is not triggering in my page .Is there any other way to do this.
Last edited by jnaneswari; Sep 2nd, 2006 at 03:04 AM.
-
Sep 2nd, 2006, 01:45 PM
#11
Re: [2005] Regarding user control in asp.net 2005
-
Sep 4th, 2006, 12:58 AM
#12
Thread Starter
Addicted Member
Re: [2005] Regarding user control in asp.net 2005
in class level i used something like this.
VB Code:
Public WithEvents btnAdd As WebControls.Button
Then i created event handler for that button
VB Code:
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
//some code here
End sub
please help me solve this
Thanks for the reply
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|