Thursday, March 22, 2012

setting the PostBackUrl property

how can I programmatically set the PostBackUrl property (for a specific aspx page) for a button control?

Let me explain:

I have a button that when fired utilizes the postbackurl property, which has been set in the properties window of the button control. How can I set this programmatically based on validation, in other words my button is fired, validation occurs - if valid the postbackurl will execute - if not valid the postbackurl will not execute leaving the user to stay on current page until validation occurs.

Hope this makes sense!?

thanks

Eric

Have a look at the following links:

http://weblogs.asp.net/despos/archive/2005/06/17/413553.aspx

http://www.odetocode.com/Articles/421.aspx


ekeefauver:

in other words my button is fired, validation occurs - if valid the postbackurl will execute - if not valid the postbackurl will not execute leaving the user to stay on current page until validation occurs.

it is even possible if you set postbackurl in design mode... check out this code below.,

<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"ValidationGroup="test">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"ControlToValidate="TextBox1"
ErrorMessage="Required to enter."ValidationGroup="test">
</asp:RequiredFieldValidator><br />
<asp:Button ID="Button1" runat="server"PostBackUrl="~/Default2.aspx" Text="Button"
ValidationGroup="test" />
</div>
</form>
</body>
</html>

hope i understood your question...


thanks codeasp, the RequiredFieldValidator control worked.

Appreciate the help (links)!

Eric

0 comments:

Post a Comment