trying to create a smile/stupid webapp,
i would like to have a disclamer at the top and 2 buttons (accept/decline) and when the user clicks accept it sends them to a website I specify and decline sends them off somewhere esle.
the design i would like is attaches just don;t know how to get the buttons to react like i want.
Hope someone can assist me
Thanks...
here is the site were i posted what i have done so far...
www.syscpupower.com
and below is the code.
now what i would like to achevive for validataion issues is to add a text box where the end user would type there name, then when there name is typed, then and only then would they be able to click accept...
How would i acheive this function...
You need to subscribe to the OnClick event of the Button control and then use Response.Redirect on OnClick.
i.e.
<asp:Button ID="Decline" OnClick="Decline_Click" runat="server" />
protected void Decline_Click(object sender, EventArgs e)
{
Response.Redirect("http://www.google.com");
}
Use the RequiredField validator and the button wont post untill the textbox is filled.
<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"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button1" /> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter name" ControlToValidate="TextBox1"> </asp:RequiredFieldValidator> </div> </form></body></html>
If you dont want the validation for a button, you need to set the property CausesValidation = False of that button. In the page if you want to check if the page is valid or not
protected void Page_Load(object sender , EventArgs e)
{
if (Page.IsValid)
// do something
}
Thanks
ok i do get that, but when they click the button to accept i would like for the page to go to another website...
I think you are getting confused. This is pretty simple and straightforward.
Step 1: Add a required field validator(or any other validator based on what type of validation you need) to a textbox so that the posting will happen only when the text box has value.
Step2:Define button click events for Accept and Decline. Response.Redirect them to whereeveryouwant.com
dguilloryjr:
...when they click the button to accept i would like for the page to go to another website...
It will redirect to the page you specified provided there is some text entered in the textbox. RequiredField validator will check if a value is given or not for a control, to which it was set.
Thanks
ok cool thanks, here is my code below:
using
System;using
System.Data;using
System.Configuration;using
System.Web;using
System.Web.Security;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Web.UI.WebControls.WebParts;using
System.Web.UI.HtmlControls;public
partialclass_Default : System.Web.UI.Page{
protectedvoid Page_Load(object sender,EventArgs e){
}
protectedvoid Button1_Click(object sender,EventArgs e){
Response.Redirect(
"http://www.hotmail.com");}
}
Please post your aspx code too where you have defined your buttons and validator.
1"C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>23"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">45<html xmlns="http://www.w3.org/1999/xhtml" >6"server">78910 "form1" runat="server">1112 "HyperLink1" runat="server" NavigateUrl="http://www.yahoo.com"13 Style="z-index: 100; left: 410px; position: absolute; top: 322px" Target="_blank" Visible="False">Decline</asp:HyperLink>14 <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="https://www.checkmytrip.com"15 Style="z-index: 101; left: 276px; position: absolute; top: 325px" Target="_blank" Visible="False">Accept16
"z-index: 107; left: 0px; position: absolute; top: 189px">17 18"z-index: 108; left: 157px; width: 411px; position: absolute; top: 18px;19 height: 160px">20
21 24"3" rowspan="3" style="text-align: center">22Please accept to view your detailed trip information. 2325 2627 2829 "Button1" runat="server" OnClick="Button1_Click" Style="z-index: 102;30 left: 268px; position: absolute; top: 268px" Text="Accept" Width="60px">31 "Button2" runat="server" OnClick="Button2_Click" Style="z-index: 103;32 left: 399px; position: absolute; top: 268px" Text="Decline" Width="64px">33 "Label1" runat="server" Style="z-index: 104; left: 233px; position: absolute;34 top: 198px" Text="Please Enter Your First and Last Name!" Width="273px">35 "TextBox1" runat="server" Style="z-index: 105; left: 252px; position: absolute;36 top: 228px" Width="216px">37 "RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"38 ErrorMessage="FirstName LastName" Font-Size="12px" Style="z-index: 109; left: 481px;39 position: absolute; top: 228px">404142434445
AutoEventWireup="true" - All Page events triggered automatically.
private void Button1_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
Response.Write ("www.google.com");
}
}
private void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
args.IsValid = (CheckBox1.Checked == true);
}
<%@. Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="WebApplicationTest.WebForm3" %>
<HTML>
<HEAD>
<title>WebForm3</title>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:CheckBox id="CheckBox1" style="Z-INDEX: 101; LEFT: 240px; POSITION: absolute; TOP: 112px"
runat="server" Text="I Accept"></asp:CheckBox>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 240px; POSITION: absolute; TOP: 144px" runat="server"
Text="Submit"></asp:Button>
<asp:CustomValidator Runat="server" ErrorMessage="You must Accept" ID="CustomValidator1" style="Z-INDEX: 103; LEFT: 368px; POSITION: absolute; TOP: 152px"></asp:CustomValidator>
</form>
</body>
</HTML>
I guess you messed up with the z-order. Check this sample and its working fine
html:
<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Good" %><!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="TextBox" runat="server" ></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click2" /><br /> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox" ErrorMessage="Enter a name"></asp:RequiredFieldValidator> </div> </form></body></html>
code behind:
public partialclass _Default : System.Web.UI.Page {protected void Page_Load(object sender, EventArgs e) { }protected void Button1_Click2(object sender, EventArgs e) { Response.Redirect("http://www.yahoo.com"); }}
Thanks
what was the problem with the z order?
If z-order is not defined properly, the layers overlap and so may be you are not able to see the error message of requiredfield validator.
Thanks
It is the z-index property in CSS. When items are absolutely positioned, they can overlap. The order that they are displayed is determined by the z-index.
No comments:
Post a Comment