I am going to use ajax for my web form app without any update panels. so I have noticed that I can use jquery ajax for this purpose.so there is a form with a dropdown box within that are some IDs.
When I select The ID from drop down, I want to show my ajax loader for moments and after that I want to show the result. the result will display in some label controls.
so this is my Default.aspx page :
<div style="text-align: center; width: 500px; margin: 0 auto 0 auto;">
<asp:DropDownList ID="idDropDownBox" runat="server" >
</asp:DropDownList>
<span>Pick ID </span>
<br />
<img alt="" id="loader" src="ajax-loader.gif" />
<table>
<tr>
<td>
<asp:Label ID="lblName" ClientIDMode="Static" runat="server" Font-Names="Tahoma" Text=""></asp:Label>
</td>
<td style="font: 11px tahoma;">
Name
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblFamily" ClientIDMode="Static" runat="server" Font-Names="Tahoma" Text=""></asp:Label>
</td>
<td style="font: 11px tahoma;">
Family
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblPhone" ClientIDMode="Static" runat="server" Font-Names="Tahoma" Text=""></asp:Label>
</td>
<td style="font: 11px tahoma;">
Phone
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblEmail" ClientIDMode="Static" runat="server" Font-Names="Tahoma" Text=""></asp:Label>
</td>
<td style="font: 11px tahoma;">
Email
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblAddress" ClientIDMode="Static" runat="server" Font-Names="Tahoma" Text=""></asp:Label>
</td>
<td style="font: 11px tahoma;">
Address
</td>
</tr>
</table>
</div>
So I decided to create an another page "GetCustomer.aspx" which by a query string , fetches the ID and then , it select all info from data base and save them in sessions.
here is the code behind of GetCustomer.aspx :
protected void Page_Load(object sender, EventArgs e)
{
AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
if (Request.QueryString.Keys.Count > 0)
{
string id = Request.QueryString[0];
CustomersDBEntities db = new CustomersDBEntities();
IQueryable<tblCustomer> allInfo = (from x in db.tblCustomers
where x.ID == int.Parse(id)
select x);
Session["Name"] = allInfo.ElementAt(1).ToString();
Session["Family"] = allInfo.ElementAt(2).ToString();
Session["Phone"] = allInfo.ElementAt(3).ToString();
Session["Email"] = allInfo.ElementAt(4).ToString();
Session["Address"] = allInfo.ElementAt(5).ToString();
}
}
finally I started to write a javascript script like below , but in success function ! what should am I Do ?
$(document).ready(function(){
$('idDropDownBox').change(function(){
$.ajax({
type:"POST",
contentType:"application/json; charset=UTF-8",
data:"{CID:'"+ $('idDropDownBox').val() + "'}",
url:'Default.aspx/GetCustomer",
dataType:"json",
success:function(data){
//what should i do here
}
});
});
});
Thanks for responses...
If my understanding is correct, you want to use the output of an ASP.Net page as the source for an AJAX call.
This is not the traditional way to work with ASP.Net though, but still you can do it
This is a simple example:
Output
ASPX - Target (empty, remove all html tags)
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Empty.aspx.cs" Inherits="WebApplication1.Empty" %>
ASPX - Target code behind
protected void Page_Load(object sender, EventArgs e)
{
this.Response.ContentType = "application/json";
var id = this.Request.QueryString["id"];
// simulate your query using the id property
var q = Enumerable.Range(1, 10);
// set the following values using your real objects
var f = new
{
Name = "your name " + id,
Fam = "your family " + id,
Phone = "your phone " + id,
Email = "your email " + id,
Address = "your address" + id
};
this.Response.Write(JsonConvert.SerializeObject(f));
}
ASPX - Caller
Note, the table shown in this example, is exactly your code, I just copied
<script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
function getData(id) {
$.ajax({
type: "GET",
url: '<%: this.ResolveClientUrl("~/Empty.aspx") %>',
dataType: "json",
data: 'id=' + id,
contentType: "application/json; charset=utf-8;",
success: function (msg) {
$("#<%: this.lblName.ClientID %>").text(msg.Name);
$("#<%: this.lblFamily.ClientID %>").text(msg.Fam);
$("#<%: this.lblPhone.ClientID %>").text(msg.Phone);
$("#<%: this.lblEmail.ClientID %>").text(msg.Email);
$("#<%: this.lblAddress.ClientID %>").text(msg.Address);
}
});
}
$(function () {
$("#<%: this.ddl.ClientID %>").change(function () {
getData($(this).val());
});
});
</script>
<asp:DropDownList runat="server" ID="ddl">
<asp:ListItem Text="1" Value="1" />
<asp:ListItem Text="2" Value="2" />
</asp:DropDownList>
<table>
<tr>
<td>
<asp:Label ID="lblName" ClientIDMode="Static" runat="server" Font-Names="Tahoma" Text=""></asp:Label>
</td>
<td style="font: 11px tahoma;">
Name
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblFamily" ClientIDMode="Static" runat="server" Font-Names="Tahoma" Text=""></asp:Label>
</td>
<td style="font: 11px tahoma;">
Family
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblPhone" ClientIDMode="Static" runat="server" Font-Names="Tahoma" Text=""></asp:Label>
</td>
<td style="font: 11px tahoma;">
Phone
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblEmail" ClientIDMode="Static" runat="server" Font-Names="Tahoma" Text=""></asp:Label>
</td>
<td style="font: 11px tahoma;">
Email
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblAddress" ClientIDMode="Static" runat="server" Font-Names="Tahoma" Text=""></asp:Label>
</td>
<td style="font: 11px tahoma;">
Address
</td>
</tr>
</table>
Have your GetCustomer to return html portion you need to display and in success: handler of $.ajax add code that appends that html to desired container, like $('#someContainer').append(data);
Related
LinkButton OnClick(LoadDocumentVersion) is Not Frie inside Update panal here is my Code in aspx page I tried using UpdateMode="Conditional" it is not fire and asyncpostback also used it is not fire
<pre>LinkButton OnClick(LoadDocumentVersion) is Not Frie inside Update panal
</pre>
<asp:UpdatePanel ID="Aspx_UpdatePanel_DocumentVersion" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:LinkButton ID="Aspx_LinkButton_DocumentVersion" runat="server" Style="float: right; margin: 2px 5px 2px 0;" CssClass="Label_Text9"
OnClick="LoadDocumentVersion" />
<asp:UpdateProgress runat="server" AssociatedUpdatePanelID="Aspx_UpdatePanel_DocumentVersion"
DynamicLayout="true">
<ProgressTemplate>
<img src="Images/loading.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<table border="0" width="100%" cellpadding="0" cellspacing="0" align="center" style="float: left;">
<tr valign="top">
<td style="padding: 5px;" align="center">
<asp:Repeater ID="Aspx_Repeater_DocumentVersions" runat="server">
<HeaderTemplate>
<table border="0" width="100%" cellpadding="0" cellspacing="0" align="center">
<tr valign="top" align="left" class="border_spacing">
<td class="Heading_border_left_spacing">
<asp:Label ID="Label1" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_FileName %>" />
</td>
<td class="Heading_border_withoutspacing">
<asp:Label ID="Label2" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_Type %>" />
</td>
<td class="Heading_border_withoutspacing">
<asp:Label ID="Label3" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_Size %>" />
</td>
<td class="Heading_border_right_spacing">
<asp:Label ID="Label4" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_Created_By %>" />
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr valign="middle" align="left" height="25px">
<td class="border_left_spacing">
<a class="Anchor_Text9_Grey" href="DownloadAttachment.aspx?InternalPath=<%#( (System.Data.DataRowView)(Container.DataItem)).Row["InternalPath"].ToString () %>&InternalFileName=<%#( (System.Data.DataRowView)(Container.DataItem)).Row["InternalFileName"].ToString () %>&ExternalFileName=<%#( (System.Data.DataRowView)(Container.DataItem)).Row["ExternalFileName"].ToString () %>"
onclick='javascript:SafeHandleURL(this, "DownloadAttachment.aspx", "<%#( (System.Data.DataRowView)(Container.DataItem)).Row["InternalPath"].ToString ().Replace ( #"\", #"\\" ) %>", "<%#( (System.Data.DataRowView)(Container.DataItem)).Row["InternalFileName"].ToString () %>", "<%#( (System.Data.DataRowView)(Container.DataItem)).Row["ExternalFileName"].ToString () %>" );'>
<asp:Label ID="Label5" runat="server" Text='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["ExternalFileName"].ToString () %>'
CssClass="Label_Text9" /> </a>
</td>
<td class="border_withoutspacing">
<asp:Label ID="Label6" runat="server" CssClass="Label_Text9" Text='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["Type"].ToString () %>' />
</td>
<td class="border_withoutspacing Label_Text9">
<asp:Label ID="Label7" runat="server" CssClass="Label_Text9" Text='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["FileSize"].ToString () %>' />
<asp:Label ID="Label8" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_Bytes %>" />
</td>
<td class="border_right_spacing">
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["CreatedBy"].ToString () %>'
CssClass="Label_Text9" CommandArgument='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["CreatedByID"].ToString () %>'
OnCommand="GoToEmployee" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr height="10px">
<td colspan="3" />
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
CodeBehind.cs
protected void LoadDocumentVersion(object sender, EventArgs e)
{
try
{
string zszFolderID = "";
string zszDocumentID = "";
string zszIsPublic = "";
EMSBLCommon.AddToLog("Document", "CRM", "View Document Versions", "");
string zszUpdateDocument = Aspx_HiddenField_DocumentPath.Value;
string zszDocumentPath = zszUpdateDocument.Substring(0, zszUpdateDocument.LastIndexOf('/'));
string zszDocumentName = zszUpdateDocument.Substring(zszUpdateDocument.LastIndexOf('/') + 1);
zszFolderID = GetFolderID(zszDocumentPath, ref zszIsPublic);
zszDocumentID = EMSBLCRM.GetDocumentID(zszFolderID, zszDocumentName).ToString();
if (!zszDocumentID.Equals("0"))
LoadDocumentAttachments(zszDocumentID);
}
catch (Exception ex)
{
Utilities.SendCrashEMail(ref ex);
}
}
Make sure AutoEventWireup="true" in your Page directive
Make sure you do not get errors, either client-side or server-side. Attach a debugger and step through your code to make sure of that
Your button cannot be clicked as it is because it is invisible, so I assume you invoke the click via JavaScript. To do that for a link button, you need to evaluate its href attribute: eval(document.getElementById("<%=Aspx_LinkButton_DocumentVersion.ClientID%>").getAttribute("href"));
make sure all webresource requests pass (i.e., 200 or 300s status codes). This is how the MS AJAX frameworks is fetched.
Make sure your script manager is the first control after the <form> tag and that all subsequent AJAX-enabled stuff is inside the <form> as well.
On my form,I am having one drop down list.I have filled drop down list on page load event.Even i have check if not is post back.My drop down list's auto post back property is true.But still the event is not firing.I have to show some value in text box on selected index changed of drop down list.
my design code is as below:
enter code here
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div>
<table class="tblContentcss">
<tr>
<td class="tdContent1css">
<asp:Label runat="server" ID="lblUserRole" Text="Role"></asp:Label>
</td>
<td class="tdContent2css">
:
</td>
<td class="tdContent3css">
<asp:TextBox runat="server" ID="txtUserRole" Text="User" ReadOnly="true"></asp:TextBox>
</td>
</tr>
<tr>
<td class="tdContent1css">
<asp:Label runat="server" ID="lblUserID" Text="User ID"></asp:Label>
</td>
<td class="tdContent2css">
:
</td>
<td class="tdContent3css">
<asp:DropDownList ID="ddlUserID" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlUserID_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="tdContent1css">
<asp:Label runat="server" ID="lblUserName" Text="User Name"></asp:Label>
</td>
<td class="tdContent2css">
:
</td>
<td class="tdContent3css">
<asp:TextBox runat="server" ID="txtUserName" AutoPostBack="true"></asp:TextBox>
</td>
</tr>
<tr>
<td class="tdContent1css">
<asp:Label runat="server" ID="lblUserPassword" Text="Password"></asp:Label>
</td>
<td class="tdContent2css">
:
</td>
<td class="tdContent3css">
<asp:TextBox runat="server" ID="txtPassword" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td class="tdContent1css">
<asp:Label runat="server" ID="Label1" Text="Password"></asp:Label>
</td>
<td class="tdContent2css">
:
</td>
<td class="tdContent3css">
<asp:Button runat="server" ID="btnSave" Text="Save" OnClick="btnSave_Click" />
</td>
</tr>
</table>
</div>
</asp:Content>
and in.cs on page_load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillUserID();
}
}
protected void ddlUserID_SelectedIndexChanged(object sender, EventArgs e)
{
fillUserID();
SqlConnection con = dal.GetConnection();
dsUserName = new DataSet();
query = "SELECT CUSTID,(FNAME+' '+MNAME+' '+LNAME) AS USERNAME FROM CUSTOMER where CUSTID=" + Convert.ToInt32(ddlUserID.SelectedValue) + "";
dsUserName = dal.ReturnDataset(query, con);
if (dsUserName.Tables.Count > 0 && dsUserName.Tables[0].Rows.Count > 0)
{
txtUserName.Text = dsUserName.Tables[0].Rows[0]["USERNAME"].ToString();
}
}
what is the problem,i am not getting.
Suggest me any solution
When the autopostback is set True, after the page is rendered, a javascript is added on the onchange event of the dropdown (SELECT in HTML) to trigger the postback,
View the source after the page is rendered and check whether the javascript is getting added to the onchange event of the dropdown.
If you are adding some javascript on the onchange event of the dropdown in the code-behind, that might also stop the page to postback.
I get that from this link: https://www.codeproject.com/Questions/138183/Drop-down-selected-index-change-event-not-working
I have a List of Client Displayed in Repeater. I have a Details Button in Repeater which displays the Details of Client when Clicked. For Sample now just added 'ClientName' only. *When i Click on 'Details' LinkButton in Repeater it Displays the Details of Selected Row. But, this causes FullPage Post Back! Which i want to Prevent. Just i want to Update the Panel which displays the Details when row is selected from Repeater*.
In .aspx page:
<script>
function ShowPopUp() {
var listItemsRegion = document.getElementById('popup');
popup.style.display = "block";
}
function ClosePopup() {
var listItemsRegion = document.getElementById('popup');
popup.style.display = "none";
}
</script>
<asp:Repeater ID="RepDetails" runat="server" OnItemCommand="RepDetails_ItemCommand">
<HeaderTemplate>
<table class="tabl">
<tr style="background-color: #808080; color: White">
<td class="lblCenter">
<asp:Label ID="Label4" runat="server" Text="City" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:Label ID="Label3" runat="server" Text="Age" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:Label ID="Label1" runat="server" Text="Gender" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:Label ID="Label5" runat="server" Text="Details" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="<%# Container.ItemIndex % 2 == 0 ? "rowEven" : "rowOdd" %>">
<td class="lblCenter">
<asp:Label ID="lblCity" runat="server" Text='<%#Eval("City") %>' /></td>
<td class="lblCenter">
<asp:Label ID="lblAge" runat="server" Text='<%#Eval("Age") %>' /></td>
<td class="lblCenter">
<asp:Label ID="lblGen" runat="server" Text='<%#Eval("Gender") %>' CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:LinkButton ID="lblDetails" runat="server" CommandName="Display"
CommandArgument='<%#Eval("ID") %>'>Details</asp:LinkButton></td>
<asp:Label ID="rlblClientname" runat="server" Text='<%#Eval("Client") %>' Visible="false"></asp:Label>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<div id="popup" style="display: none">
<asp:UpdatePanel ID="UpdatePanel6" runat="server">
<ContentTemplate>
<table width="80%" align="center">
<tr>
<td> </td>
<td width="30%"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<asp:Label ID="Label15" runat="server" CssClass="lbl" Text="Client Code"></asp:Label>
</td>
<td>
<asp:Label ID="lblClientName" runat="server" CssClass="lbl"></asp:Label>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input id="Button2" type="button" value="Close" onclick="ClosePopup();" class="but" /> </td>
</tr>
</table>
</ContentTemplate>
<%-- <Triggers>
<asp:AsyncPostBackTrigger ControlID="RepDetails" EventName="RepDetails_ItemCommand" />
</Triggers>--%>
</asp:UpdatePanel>
</div>
In Repeater Item Command:
protected void RepDetails_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Display")
{
LinkButton lblDetails = (LinkButton)e.Item.FindControl("lblDetails");
Label rlblClientname = (Label)e.Item.FindControl("rlblClientname");
if (lblDetails != null && e.CommandArgument != null)
{
string val = e.CommandArgument.ToString();
if (rlblClientname != null && rlblClientname.Text != string.Empty)
{
lblClientName.Text = rlblClientname.Text;
}
string scrpt = "ShowPopUp();";
Page.ClientScript.RegisterStartupScript(this.GetType(), "s", scrpt, true);
}
}
}
This causes Full Page Post Back Which i want to Prevent.Onclick of Repeater row the details must be displayed with AsynPostBack. When adding Trigger Event to 'popup' div then it say control could not be found
Help Appreciated!
Thanks!
You have one of two Options:
1) Uncomment this code and change EventName="RepDetails_ItemCommand" to EventName="ItemCommand"
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RepDetails" EventName="ItemCommand" />
</Triggers>
2) Put the Repeater in the <ContentTemplate> of the UpdatePanel
I have a repeater control rptbrand in which one textbox txtMultiBrand is there and after each repeating time when i click btnAddBrand button i want validation for unique entries in textbox, here is my aspx code
<table width="100%">
<asp:Repeater ID="rptBrand" runat="server" OnItemDataBound="rptBrandDetail_ItemDataBound">
<ItemTemplate>
<tr>
<td align="right" `enter code here`width="150">
Brand<asp:Label ID="lblBrandNum" runat="server"></asp:Label>
<span class="msgred">*</span> :
</td>
<td align="left">
<table width="100%">
<tr>
<td align="left" width="20%">
<asp:TextBox ID="txtMultiBrand" CssClass="imageSearch" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator14" runat="server" ValidationGroup="VGrpMultiSave"
ControlToValidate="txtMultiBrand" ErrorMessage="Brand Required" Display="none"
SetFocusOnError="True"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ValidationGroup="VGrpSave"
ControlToValidate="txtMultiBrand" ErrorMessage="Brand Required" Display="none"
SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
<td align="left">
<asp:ImageButton ID="btnDelete" runat="server" CausesValidation="false" CommandName="CmdDelete"
CommandArgument='<%# Eval("SrNo") %>' ToolTip="Delete" ImageUrl="images/b_drop.png"
OnCommand="rptBrand_Command" Width="16" Height="16" OnClientClick="javascript:return confirm('Are you sure you want to remove brand?')" />
</td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr>
<td align="right" width="150">
</td>
<td>
<asp:Button ID="btnAddBrand" runat="server" Text="Add more" ValidationGroup="VGrpMultiSave"
OnClick="btnAddBrand_Click" />
<asp:ValidationSummary ID="ValidationSummary2" runat="server" DisplayMode="List"
ShowMessageBox="True" ShowSummary="False" ValidationGroup="VGrpMultiSave" />
</td>
</tr>
</table>
Using jQuery:
IT IS WORKING
Check the below link:
http://jsfiddle.net/NtF7h/
$(function () {
$("#<%=btnAddBrand.ClientID%>").on("click", function (event) {
var valueArray = new Array(); ;
$("input[id*='txtMultiBrand']").each(function (index) {
if ($.inArray($(this).val(), valueArray) == -1) {
valueArray[index] = $(this).val();
}
else {
alert("Duplicate Entry Found.");
event.preventDefault();
return false;
}
});
});
});
I have a web feedback wizard and when I tested it in the browser, clicking the next button, it goes fine from step 1 to step 2 but then it refuses to go to step 3. Also, I tried to keep the focus on the first text box in each step, but it still isn't working right. when I click 'next' the step moves (as i said it works from Contact Info to Comments) but it scrolls up to the top of the web page and loses focus from the wizard. which is annoying.
so I have two problems: (1) my wizard only goes to two out of the four steps. (2) the wizard loses its focus.
here is what i have in my wizard control:
<asp:Wizard ID="Wizard1" runat="server" BackColor="#E6E2D8"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
Font-Names="Verdana" Font-Size="0.8em" ActiveStepIndex="0" Height="371px"
Width="691px" style="margin-top: 178px"
onfinishbuttonclick="Wizard1_FinishButtonClick" TabIndex="1"
onactivestepchanged="Wizard1_ActiveStepChanged"
onload="Wizard1_ActiveStepChanged" onnextbuttonclick="OnNextButtonClick"
onprerender="Wizard1_ActiveStepChanged" >
<HeaderStyle BackColor="#666666" BorderColor="#E6E2D8" BorderStyle="Solid"
BorderWidth="2px" Font-Bold="True" Font-Size="0.9em" ForeColor="White"
HorizontalAlign="Center" />
<NavigationButtonStyle BackColor="White" BorderColor="#C5BBAF"
BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="2em"
ForeColor="#1C5E55" />
<SideBarButtonStyle ForeColor="#855A21" />
<SideBarStyle BackColor="#E3D3AC" Font-Size="0.9em" VerticalAlign="Top" />
<StepStyle BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderStyle="Solid"
BorderWidth="2px" VerticalAlign="Top" />
<WizardSteps>
<asp:WizardStep ID="WizardStep1" runat="server" Title="Contact Info"
StepType="Start">
<table cellpadding="10" class="style1">
<tr>
<td class="style2">
Your Name</td>
<td class="style3">
<asp:TextBox ID="nametxt" runat="server" style="margin-left: 0px"
Width="137px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="nametxt" ErrorMessage="Please Enter your name"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style5">
Email</td>
<td class="style6">
<asp:TextBox ID="emailtxt" runat="server"></asp:TextBox>
</td>
<td class="style6">
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="emailtxt" ErrorMessage="Please enter your email address"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style5">
City</td>
<td class="style6">
<asp:TextBox ID="citytxt" runat="server"></asp:TextBox>
</td>
<td class="style6">
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="Please enter your city or town"
ValidationExpression="^[a-zA-Z0-9\s.\-]+$" ControlToValidate="citytxt"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style5">
State</td>
<td class="style6">
<asp:TextBox ID="statebox" runat="server" MaxLength="2" Width="47px"></asp:TextBox>
</td>
<td class="style6">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="statebox" ErrorMessage="Please enter your state"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style3" colspan="2">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" Width="163px" />
</td>
</tr>
</table>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep2" runat="server" Title="Comments"
StepType="Step">
<table cellpadding="10" class="style1">
<tr>
<td class="style4">
Comments<br />(no more than 500 characters)</td>
<td>
<asp:TextBox ID="txtcomments" runat="server" Height="55px" TextMode="MultiLine"
Width="233px"></asp:TextBox>
</td>
<td>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ClientValidationFunction="ValidateComments" ControlToValidate="txtcomments"
ErrorMessage="Please enter no more than 500 characters"
OnServerValidate="CustomerValidator1"></asp:CustomValidator>
</td>
</tr>
<tr>
<td class="style4">
Rating<br />(1-5)</td>
<td>
<asp:TextBox ID="txtrating" runat="server"></asp:TextBox>
</td>
<td>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="txtrating" ErrorMessage="Use a number between 1-5"
MaximumValue="5" MinimumValue="1"></asp:RangeValidator>
</td>
</tr>
<tr>
<td class="style4">
</td>
<td colspan="2">
<asp:ValidationSummary ID="ValidationSummary2" runat="server" Height="42px" />
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="txtcomments"></asp:CompareValidator>
</td>
</tr>
</table>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep3" runat="server" Title="Summary"
StepType="Finish">
<table cellpadding="10" class="style1">
<tr>
<td class="style7">
<h3>Summary:</h3>
<br />
<asp:Label ID="nameLabel" runat="server" AssociatedControlID="namelabel"></asp:Label>
</td>
<td class="style7">
</td>
</tr>
<tr>
<td>
<asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Emaillabel" ></asp:Label></td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Label ID="cityLabel" runat="server" AssociatedControlID="citylabel"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Label ID="stateLabel" runat="server" AssociatedControlID="statelabel"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Label ID="commentslabel" runat="server" AssociatedControlID="commentslabel"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Label ID="ratinglabel" runat="server" AssociatedControlID="txtrating"></asp:Label>
</td>
<td>
</td>
</tr>
</table>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep4" runat="server" Title="Complete"
StepType="Complete">
<br />
<br />
<br />
<br />
<br />
<br />
<h3> Thank You!</h3>
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
here is what i have in the behind code: (c#)
protected void Page_Load(object sender, EventArgs e)
{
//Prevent display of sitemap on default page.
SiteMapNode node = SiteMap.CurrentNode;
if (node.ParentNode == null)
{
SiteMapPath1.Visible = false;
Wizard1.Visible = false;
}
nameLabel.Text = nametxt.Text;
EmailLabel.Text = emailtxt.Text;
cityLabel.Text = citytxt.Text;
stateLabel.Text = statebox.Text;
commentslabel.Text = txtcomments.Text;
ratinglabel.Text = txtrating.Text;
}
public void OnNextButtonClick(object sender, WizardNavigationEventArgs e)
{
this.Wizard1.Focus();
Wizard1_ActiveStepChanged(sender, e);
}
private TextBox FindFirstTextBox(Control c)
{
TextBox nothing = null;
Control results;
if ((c == null))
{
return nothing;
}
if (c.GetType() == typeof(TextBox))
{
return (TextBox)c;
}
foreach (Control child in c.Controls)
{
results = FindFirstTextBox(child);
if (results != null && (results.GetType() == typeof(TextBox)))
{
return (TextBox)results;
}
else
{
return nothing;
}
}
return nothing;
}
protected void Wizard1_ActiveStepChanged(object sender, System.EventArgs e)
{
// Set the focus to the first TextBox in the current step
WizardStepBase currentWizardStep = Wizard1.ActiveStep;
// Find the first TextBox
TextBox firstTextBox = FindFirstTextBox(currentWizardStep);
// If we found a TextBox, set the Focus
if (!(firstTextBox == null))
{
firstTextBox.Focus();
}
}
Ok that is because... you have a compare validator on your txtComments field in the 2nd step of your wizard...I would recommend to either fix it or remove it...here is the code that I am referring to (in your Wizard Step 2)
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="txtcomments"></asp:CompareValidator>
The things that are missing in the above code are:
Set "ControlToCompare" property.
Set an error message...
Update for your second problem
To keep focus on your first text box...of each tab and to keep scroll position...follow below steps...
Step 1 In your Page_Load event...add the below line of code
nametxt.Focus(); // This will make sure that your nametxt texbox has focus when your page loads for the first time
Step 2 Your FindFirstTextBox method's code can be as simple as below...so update it to the code below...
// This code is pretty much self explanatory
private TextBox FindFirstTextBox(Control c)
{
foreach (Control child in c.Controls)
{
if (child is TextBox)
return (TextBox)child;
}
//If we didn't find a TextBox
return null;
}
Step 3 Update your Wizard_ActiveStepChanged event to below...
protected void Wizard1_ActiveStepChanged(object sender, System.EventArgs e)
{
// Set the focus to the first TextBox in the current step
WizardStepBase currentWizardStep = Wizard1.ActiveStep;
// Find the first TextBox
TextBox firstTextBox = FindFirstTextBox(currentWizardStep);
// If we found a TextBox, set the Focus
if (Page.IsPostBack && firstTextBox != null)
{
firstTextBox.Focus();
}
}
In the above event code, I have changed the if statement to have an additional check for page.IsPostBack...this is because the Focus method will throw an exception...since this event is being called before your OnLoad and OnRender...Its pretty much up to you to figure out why you are calling this step so early...
Step 4 Finally, to fix your scrolling problem...you need to use an Update panel...please see below code snippet...
// Your Update Panel needs a Script Manager to work
<asp:scriptManager runat="server" ID="sm"></asp:scriptManager>
<asp:UpdatePanel runat="server" ID="panel" UpdateMode="Always">
<ContentTemplate>
// ALL YOUR CONTENT MARK UP GOES HERE
</ContentTemplate>
</asp:UpdatePanel>
This should probably fix your second problem...