drop down list Selected index changed event not working - asp.net

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

Related

Taking a textbox's text in a listview

I have a ListView, and i have an asp:TextBox in it:
<table>
<asp:ListView ID="Users" runat="server"
DataKeyNames="Email" onitemediting="Users_ItemEditing"
onitemupdating="Users_ItemUpdating">
<LayoutTemplate>
<tr>
<td style=" width:34%;border-bottom:1px solid black;">Name</td>
<td></td>
</tr>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("name") %>
</td>
<td>
<asp:LinkButton ID="Edit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td>
<asp:TextBox ID="Name" runat="server" Text='<%# Bind("name") %>'></asp:TextBox>
</td>
<td>
<asp:LinkButton ID="Update" runat="server" CommandName="Update">Update</asp:LinkButton>
</td>
</tr>
</EditItemTemplate>
</asp:ListView>
</table>
when i change the text in the text box and then try to get it in the code behind like this:
protected void Users_ItemEditing(object sender, ListViewEditEventArgs e)
{
this.Users.EditIndex = e.NewEditIndex;
BindTheListView();
}
protected void Users_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
string Name=((TextBox)Users.Items[e.ItemIndex].FindControl("Name")).Text;
this.Users.EditIndex = -1;
BindTheListView();
}
*BindTheListView() Binds the listview Users, it works.
it takes the original text of the TextBox, the <%# Bind("name") %> instead of what i have just changed.
The update function is a lot longer so i put only what i think is needed. i know the Name recives the text that wast before in the textbox because the updtade function didnt work(it didnt change anything in the database) so i run debugg and i saw that Name recives what was before
How can i take the text that i have entered the textbox and not what was in it?
Thanks for the help
In User.ItemUpdating get new values from e.NewValues collection instead.
EDIT:
Use DataList instead of ListView:
<table>
<asp:DataList ID="Users" runat="server" DataKeyField="Email" OnEditCommand="Users_ItemEditing"
OnUpdateCommand="Users_ItemUpdating">
<HeaderTemplate>
<tr>
<td style="width: 34%; border-bottom: 1px solid black;">
Name
</td>
<td>
</td>
</tr>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("name") %>
</td>
<td>
<asp:LinkButton ID="Edit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td>
<asp:TextBox ID="Name" runat="server" Text='<%# Bind("name") %>'></asp:TextBox>
</td>
<td>
<asp:LinkButton ID="Update" runat="server" CommandName="Update">Update</asp:LinkButton>
</td>
</tr>
</EditItemTemplate>
</asp:DataList>
</table>
Code behind:
protected void Users_ItemEditing(object sender, DataListCommandEventArgs e)
{
this.Users.EditItemIndex = e.Item.ItemIndex;
BindTheListView();
}
protected void Users_ItemUpdating(object sender, DataListCommandEventArgs e)
{
string Name = ((TextBox)e.Item.FindControl("Name")).Text;
}
on Page Load use
if (!IsPostBack)
{
BindTheListView();
}

How to Update a Panel Out side Repeater on ItemCommand of Repeater using Update Panel in asp.net?

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

how to show header row either listview has data or not?

I have a list view and i want to add a header row in it which will come when the listview has data or not. in each and every condition i want it there. I have used LayOut Template to do so but its showing the Header row only if the listview has data.Then i tried EmptydataTemplate, Its showing the header row but now the button in it is not working.
My code is
<asp:UpdatePanel ID="upViewSchedule" runat="server">
<ContentTemplate>
<asp:ListView ID="lstuser" runat="server" ItemPlaceholderID="trItem" DataKeyNames="id"
OnItemDataBound="lstuser_ItemDataBound">
<LayoutTemplate>
<table cellspacing="0">
<tr class="hdrRowColor1">
<td align="left">
name
</td>
<td align="left">
salary
</td>
<td align="left">
address
</td>
<td align="left" style="border-right: 1px solid #6398cc">
Actions
</td>
</tr>
<tr class="OddRowColor">
<td align="left">
<asp:DropDownList ID="drphdrname" runat="server" Width="120px">
</asp:DropDownList>
<ajaxCtrl:CascadingDropDown ID="csddrphdrName" runat="server" TargetControlID="drpname"
Category="Name" ServicePath="~/Resources/WebService.asmx" ServiceMethod="GetName">
</ajaxCtrl:CascadingDropDown>
</td>
<td>
<asp:TextBox ID="txtaddress" runat="server" Width="110px"></asp:TextBox>
</td>
<td width="50px" class="last">
<asp:ImageButton ID="imgBtnHdrAdd" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/add_new.png"
OnClick="imgBtnHdrAdd_Click" ToolTip="Add user." />
</td>
</tr>
<tr id="trItem" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class='<%# Convert.ToBoolean(Container.DataItemIndex % 2) ? "OddRowColor" : "EvenRowColor" %>'>
<td align="left" width="138px">
<asp:DropDownList ID="drpname" runat="server" Width="120px">
</asp:DropDownList>
<asp:Label ID="lblCreatedBY" Text='<%# Eval("CreatedBy") %>' runat="server" Visible="false"></asp:Label>
<asp:Label ID="lblId" runat="server" Visible="false"></asp:Label>
<ajaxCtrl:CascadingDropDown ID="casddrpContacts" runat="server" TargetControlID="drpname"
Category="name" ServicePath="~/Resources/WebService.asmx" ServiceMethod="Getuser">
</ajaxCtrl:CascadingDropDown>
</td>
<td align="left" width="138px">
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("salary") %>' Width="110px"></asp:TextBox>
</td>
<td align="left" width="138px">
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("address") %>' Width="110px"></asp:TextBox>
</td>
<td align="left" class="last">
<asp:ImageButton ID="imgBtnEdit" runat="server" ImageUrl="~/App_Themes/ThemeNew2/images/update.png"
CommandArgument='<%# Eval("id") %>' OnClick="imgBtnEdit_Click" ToolTip="Update user" />
<asp:ImageButton ID="imgBtnDelete" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/delete.png"
CommandArgument='<%# Eval("id") %>' OnClientClick="return confirm('Are you sure you want to delete this user ?');"
ToolTip="Delete user" OnClick="imgBtnDelete_OnClick" />
</td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<table cellspacing="0">
<tr class="hdrRowColor1">
<td align="left">
name
</td>
<td align="left">
salary
</td>
<td align="left">
address
</td>
<td align="left" style="border-right: 1px solid #6398cc">
Actions
</td>
</tr>
<tr class="OddRowColor">
<td align="left">
<asp:DropDownList ID="drphdrname" runat="server" Width="120px">
</asp:DropDownList>
<ajaxCtrl:CascadingDropDown ID="csddrphdrName" runat="server" TargetControlID="drpname"
Category="Name" ServicePath="~/Resources/WebService.asmx" ServiceMethod="GetName">
</ajaxCtrl:CascadingDropDown>
</td>
<td>
<asp:TextBox ID="txtaddress" runat="server" Width="110px"></asp:TextBox>
</td>
<td width="50px" class="last">
<asp:ImageButton ID="imgBtnHdrAdd" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/add_new.png"
OnClick="imgBtnHdrAdd_Click" ToolTip="Add user." />
</td>
</tr>
<tr id="trItem" runat="server">
</tr>
</table>
</EmptyDataTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
my Code behind code is
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BIndAddress();
// BindRoleDrop();
drpAddress.Items.Insert(0, new ListItem("Select Area", ""));
drpRoom.Items.Insert(0, new ListItem("Select Room", ""));
ViewState["sortCol"] = "tblUser.id";
ViewState["sortDir"] = "Desc";
ViewState["nmbr"] = 1;
BindData(ViewState["sortCol"].ToString(), ViewState["sortDir"].ToString(), Convert.ToInt32(ViewState["nmbr"]), 7999);
}
else
{
lblMessage.Visible = false;
}
}
And one thing more please let me know how can i apply validations on these.
I did some testing locally. I found that if I have a button in the EmptyDataTemplate it's OnClick event will fire as expected as long as you do not modify the state of the ListView before the event fires.
I'm guessing therefore that you have some code that modifies the state (re-binds it for instance) of the ListView which runs before the imgBtnHdrAdd_Click event handler for the button in question.
The Page_Load method would have been the primary suspect, but based on your code it is properly checking for !IsPostBack.
I'm assuming that it is the call to BindData that is used for setting databinding the ListView. Look for other places in you code behind where that method is called and verify that none of those places are being run before the event handler for the button.

Connect Text Box to Table

I'm new in ASP.net and started my first Website Project. I want to connect the text box to my table which is "Details" please see the code below:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<p class="style2">
<br />
DETAILS FORMS</p>
<p>
<table style="width: 100%; height: 117px;">
<tr>
<td class="style4">
<asp:Label ID="Label1" runat="server" Text="ID :"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td class="style3">
</td>
</tr>
<tr>
<td class="style5">
<asp:Label ID="Label2" runat="server" Text="Date Recieved :"></asp:Label>
</td>
<td>
<asp:TextBox ID="DRInput" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style5">
<asp:Label ID="Label3" runat="server" Text="Date Commision :"></asp:Label>
</td>
<td>
<asp:TextBox ID="DCINput" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style5">
<asp:Label ID="Label4" runat="server" Text="Sender"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem>Angeles</asp:ListItem>
<asp:ListItem>Aurora</asp:ListItem>
<asp:ListItem>Bataan</asp:ListItem>
<asp:ListItem>Bulacan</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Database1ConnectionString1 %>"
SelectCommand="SELECT [Sender] FROM [Details]"></asp:SqlDataSource>
</td>
<td>
</td>
</tr>
<tr>
<td class="style10">
</td>
<td class="style11">
<asp:Button ID="Button1" runat="server" Text="Button" />
</td>
<td class="style11">
</td>
</tr>
<tr>
<td class="style6">
</td>
<td class="style7">
</td>
<td class="style7">
</td>
</tr>
</table>
</p>
</asp:Content>
And this is the Code behind it:
public partial class Data : System.Web.UI.Page
{
protected void DRInput_DataBinding(object sender, EventArgs e)
{
}
What would be my code to bind the textbox to save details in my table "Details" and when I click the button it will be save on table "Details" . Hoping anyone could help. Thanks in advance.
In you particular case it doesn't look like you're displaying a list of data but instead the details of an item.
The simple approach would be to assign the text property of the textbox as part of the page request eg within page load event of the page.
DRInput.Text = detailsModel.DRInput;
and then when the page is submitted assign the textbox's text value back to your object.
detailsModel.DRInput = DRInput.Text;
Since you're new to ASP.Net; perhaps best to start with tutorial sites for example w3schools.com/aspnet/aspnet_demo_intro.asp or asp.net/web-forms then come back and ask your questions

ASP.NET Wizard not moving to WizardStep index 3 in browser

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...

Resources