Button Click

S

shapper

Hello,

I am creating a custom control where I have a button.
Somehow my button click event is not being raised.
I tried to place different codes inside MyButton_Click and nothing
runs.
Then I added Context.Response.Redirect("http://www.google.com").
When I click the button postback is done but the page google is not
called.

I am on this for days. I looked everywhere in Google and everything
seems ok.

Could someone, please, tell me what to do to try to figure what is the
problem?

I don't know what else to try.

Thank You,
Miguel

Here is my code:
...
Public Class Contact
Inherits WebControl

Dim MyButton As New WebControls.Button

Private Sub MyButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Context.Response.Redirect("http://www.google.com")
End Sub

Private Sub MyButton_Init(ByVal sender As Object, ByVal e As
System.EventArgs)
MyButton.ID = Me.ID & "_bSubmit"
MyButton.Text = "Submit"
End Sub

Protected Overrides Sub CreateChildControls()
AddHandler MyButton.Init, AddressOf MyButton_Init
AddHandler MyButton.Click, AddressOf MyButton_Click
MyBase.Controls.Add(MyButton)
MyBase.CreateChildControls()
Me.ChildControlsCreated = True
End Sub

End Class
 
B

Brian Williams

Is this a Custom Web Control or a Web User Control?

If this was a Web User Control I would do something like this:

(User Control Event Handler)
public event EventHandler DynButton1;
protected void btnDynButton1_Click(object sender, EventArgs e)
{
OnDynButton1_Click(e);
}
protected void OnDynButton1_Click(EventArgs e)
{
if (DynButton1 != null)
DynButton1(this, e);
}


(Page that is using User Control)
protected override void OnInit(EventArgs e)
{
YourUserControlID.DynButton1 += new EventHandler(DynButton1);
}
private void DynButton1(object sender, EventArgs e)
{
// Do something...
}

Sorry it's in C# I don't do VB.

Regaards,
Brian K. Williams
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top