Juan Wajnerman
12/20/2002 4:21:00 AM
Raising the click event don't will help you, because is executed at server
side.
You can use Server.Transfer or Response.Redirect methods to redirect
execution to another page.
For example:
private void Button1_Click(object sender, EventArgs e) {
if (ValidateInfo() == true) {
Server.Transfer("test.htm");
}
}
"bk" <balinka@yahoo.com> wrote in message
news:c834935b.0212191346.54edbb94@posting.google.com...
> I am quiet new with ASP.Net programming. Any help s appreciated
> When a button is clicked on a page, i want to validate the info
> entered and load a new page,say "test.htm". For this, I have a
> HtmlAnchor object, whose HREF property i have set. I want to
> internally generate a ServerClick event for it.
>
> I tried the following, but the new page never gets loaded. Where am I
> wrong? Is there a more direct method, such as Windows
> SendMessage(WM_CLICK) for a control?
>
> using System;
> using System.Web.UI;
> using System.Web.UI.HtmlControls;
>
>
> namespace CustomCtrl
> {
> /// <summary>
> /// Summary description for CustomLink.
> /// </summary>
> public class CustomLink: HtmlAnchor, IPostBackEventHandler
> {
> // Defines the Click event.
> public event EventHandler ServerClick;
> public delegate void EventHandler (object sender, EventArgs e);
>
> // OnClick dispatches the event to delegates that
> // are registered with the Click event.
> // Controls that derive from MyButton can handle the
> // Click event by overriding OnClick
> // instead of attaching a delegate. The event data
> // is passed as an argument to this method.
> protected virtual void OnServerClick(EventArgs e)
> {
> if (ServerClick != null)
> {
> base.OnServerClick(e);
> }
> }
>
> // Method of IPostBackEventHandler that raises change events.
> public void RaisePostBackEvent(string eventArgument)
> {
> //ServerClick(this, EventArgs.Empty);
> OnServerClick(EventArgs.Empty);
> }
>
> public CustomLink(string link)
> {
> //
> // TODO: Add constructor logic here
> //
> this.HRef = link;
> }
> }
> }
>
> namespace MyWebForm
> {
> using CustomCtrl;
>
> class EventListener
> {
> private CustomLink lnk;
>
> public EventListener(CustomLink link)
> {
> lnk = link;
> lnk.ServerClick += new
> CustomCtrl.CustomLink.EventHandler(BtnClicked);
> }
>
> private void BtnClicked(object sender, EventArgs e)
> {
> }
>
> public void Detach()
> {
> lnk.ServerClick -= new
> CustomCtrl.CustomLink.EventHandler(BtnClicked);
> lnk = null;
> }
>
> }
> }
>
>
> the following code to force the click on the link:
> -------------------------------
> CustomLink lnk = new CustomLink("test.htm");
> EventListener listener = new EventListener(lnk);
> lnk.RaisePostBackEvent("Click");