Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
    tc = new TableCell();
    btnCancel = new Button();
    btnCancel.Text = "Cancel";
    btnCancel.Click += new EventHandler (btnCanel_Click ) ;
    tc.Controls.Add(btnCancel);
    tr.Controls.Add(tc);

    t.Controls.Add(tr);


    // Empty table cell
    tr = new TableRow();
    tc = new TableCell();
    tr.Controls.Add(tc);

    this.Controls.Add(t);
}

protected void btnCanel_Click(object sender, EventArgs e)
{

}



What i am tring to do is . when i click on Cancel button it redirect me to "Example.aspx".
i am create a webpart using C#

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 21-Jun-11 9:02am
v2

Why don't you set the PostbackUrl property to the url you want to redirect to? (BTW, when you do that, it will not fire the Button.Click event.
 
Share this answer
 
Comments
anjumnavid 21-Jun-11 15:36pm    
i am not sure that i want do .
i crated a Web part , which i basically Email formatted. i have name textbox, Emailaddress textbox, phonnumber textbox , message textbox, a send button and cancel button.
Its work fine , but i want when user click on send button or cancel button it redirect to given url. But i don;t know how to do that.
you could use SPUtility.Redirect Method

SPUtility.Redirect Method[^]

If this is asp.net webpart you are talking about, redirection just works fine.
 
Share this answer
 
Comments
anjumnavid 21-Jun-11 16:03pm    
Thanks vivek...
i am one more question. how do i use validations in same webpart. (for example: i want no field should be empty) i know i to it in ASP.net but i am using only C# .
anjumnavid 21-Jun-11 16:05pm    
Here is my code for one of the field.


// Message textbox
tc = new TableCell();
tc.VerticalAlign = VerticalAlign.Top;
txtMessage = new TextBox();
txtMessage.ID = "txtMessage";
txtMessage.Height = Unit.Pixel(100);
txtMessage.Width = Unit.Pixel(400);
txtMessage.TextMode = TextBoxMode.MultiLine;
txtMessage.Wrap = true;
tc.Controls.Add(txtMessage);

//Add Validator
RequiredFieldValidator _rfvContactMessage = new RequiredFieldValidator();
_rfvContactMessage.Text = "** Email Address is Required!";
_rfvContactMessage.Display = ValidatorDisplay.Dynamic;
_rfvContactMessage.ControlToValidate = _rfvContactMessage.ID;
_rfvContactMessage.ForeColor = Color.Red;
_rfvContactMessage.ValidationGroup = "Email";
tc.Controls.Add(_rfvContactMessage);

tr.Controls.Add(tc);

t.Controls.Add(tr);
Vivek Krishnamurthy 21-Jun-11 16:11pm    
I think you got the _rfvContactMessage.ControlToValidate = _rfvContactMessage.ID;
wrong it should be the ID of the control you are validationg.
anjumnavid 21-Jun-11 17:01pm    
yes i noticed.

_rftContactMessage.ControlToValidate = txtMessage.ID;

But it still not work. Any Idea>
CS1401 24-Jun-11 5:16am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900