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
Printable View
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
In your web user control, declare your event.
In the button click event inside your web user control,Code:public event EventHandler MyButtonClick;
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.Code:protected void Button4_Click(EventArgs e)
{
if(MyButtonClick != null)
{
MyButtonClick(this, e);
}
}
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
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
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.
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
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
I tried this but it is giving error
Button1 is not a member of this page
What is the name of your button? Does it have a declaration at the class level? Something like... Protected Button1 As Button?
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.
Show all your code.
in class level i used something like this.
Then i created event handler for that buttonVB Code:
Public WithEvents btnAdd As WebControls.Button
please help me solve thisVB Code:
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click //some code here End sub
Thanks for the reply