How to maintain the value? [Resolved]

Posted by Mahesh_Chs under ASP.NET on 4/28/2012 | Points: 10 | Views : 1163 | Status : [Member] | Replies : 7
Hi,

In my web page i have 2 textboxes(first textbox is for username and 2nd is for password) and two dropdownlists, based on first dropdownlist 2nd dropdownlist values will come.
when ever i am changing the value in the first dropdownlist the password values is not maintaing in the page. so how to maintain the value of the password in the roundtrips

Thank you
Regards
Mahesh




Responses

Posted by: Dotnetguy on: 4/30/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi Try this

------aspx-----------
<table>
<tr>
<td>
UserName:
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
</td>

</tr>

<tr>
<td>
Password:
</td>
<td>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
</td>

</tr>

<tr>
<td>
Country:
</td>
<td>
<asp:DropDownList ID="ddlCountry" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged">
<asp:ListItem Text="--Select--" Value="0"></asp:ListItem>
<asp:ListItem Text="India" Value="1"></asp:ListItem>
<asp:ListItem Text="USA" Value="2"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>

<tr>
<td>
State:
</td>

<td>
<asp:DropDownList ID="ddlState" runat="server" >
</asp:DropDownList>
</td>
</tr>


</table>


-------aspx.cs---------
protected void ddlCountry_SelectedIndexChanged(object sender,EventArgs e )
{
ddlState.Items.Clear();
txtPassword.Attributes.Add("value", txtPassword.Text);

if (ddlCountry.SelectedValue == "1")
{
ddlState.Items.Add(new ListItem("Andhra Pradesh","AP"));
ddlState.Items.Add(new ListItem("karnataka", "KT"));
ddlState.Items.Add(new ListItem("TamilNadu", "TL"));
}

if (ddlCountry.SelectedValue == "2")
{
ddlState.Items.Add(new ListItem("New York", "NY"));
ddlState.Items.Add(new ListItem("Michchigun", "MG"));
ddlState.Items.Add(new ListItem("Washington", "WT"));
}
}


Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ksuresh on: 4/30/2012 [Member] Starter | Points: 25
Posted by: Mahesh_Chs on: 4/30/2012 [Member] Starter | Points: 25

Up
0
Down
Hi suresh,

I know how to get the values into the dropdownlists but i want to know that, how can we maintain the value of the password in the roundtrips(that means when we select any value from one dropdownlist the it will make a roundtrip so the value of the password will be erased, but i dont want like that, i want to maintain the password value in the roundtrips)



Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patil_Rakesh on: 4/30/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Mahesh_Chs,
Please make use fo Hidden field control for storing values of password textbox..
This will help u.


Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mahesh_Chs on: 4/30/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Rakesh,

Can u please send me the code

Thank you


Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patil_Rakesh on: 4/30/2012 [Member] Starter | Points: 25

Up
0
Down
Okay buddy,
First of all send your code to my email id :- rakeshpp90@gmail.com ,
i will edit it and send back to you.
along with print screen of your form if possible.

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mahesh_Chs on: 5/2/2012 [Member] Starter | Points: 25

Up
0
Down
Hii

Thank you, nice answer

Regards
Mahesh

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response