how to stop the text box values are getting clear

Posted by Ravinderk under ASP.NET on 8/21/2012 | Points: 10 | Views : 3272 | Status : [Member] | Replies : 7
I have few textboxes and one dropdown list . And am performing the onChange event on this drop down list, but it is refreshing the page, It should not why because while refreshing the page am loosing the previous text box values which we entered to submit and save into the database. It should not happen.



Thanks
ravi




Responses

Posted by: Gopesh9 on: 8/21/2012 [Member] Starter | Points: 25

Up
0
Down
Disable the PostBack property of the Dropdown list, then it will not refresh the page every time you change the value of the dropdown list...

G. S.
.Net Developer

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

Posted by: Vasanthmvp on: 8/21/2012 [Member] Starter | Points: 25

Up
0
Down
hi,
I think the data in the text box persists after getting refreshed too..

Try this sample:

ASP:
<asp:TextBox ID="t1" runat="server" />
<asp:TextBox ID="t2" runat="server" />

<asp:DropDownList ID="dd" AutoPostBack="true" runat="server" OnSelectedIndexChanged="call">
<asp:ListItem Value="1" Text="1" />
<asp:ListItem Value="2" Text="2" />
</asp:DropDownList>

CodeBehind:

protected void call(object sender, EventArgs e)
{
Response.Write("hai");
}


If this is not appropriate, could you post your code.

Regards,


Awesome Coding !! :)

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

Posted by: Vasanthmvp on: 8/21/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Gopesh,

If we disable the autopostback property. The values of textbox remains, but no changes with respect to onselectionindex changed event occurs on the page.

Regards,

Awesome Coding !! :)

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

Posted by: Gopesh9 on: 8/21/2012 [Member] Starter | Points: 25

Up
0
Down
@Vasanth,

Thanks for your reply, Sometimes we have static texts like Dropdown list of Country or state where i dont want the page to be refreshed as it is client side scripting, for using that DropDownlist we will disable the autopostback properties of the DropDownList...

G. S.
.Net Developer

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

Posted by: Ravinderk on: 8/21/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks for your replay, This is not working in asp.net MVC3...could you plz send me the code in ASP.NET MVC3 arch....


Thanks
ravi

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

Posted by: Vasanthmvp on: 8/21/2012 [Member] Starter | Points: 25

Up
0
Down
@Gopesh,

Yes,In the case to represent static texts, where we dont include any event to occur. we set it as false.
Also,The default value of autopostback is false.

Regards,

Awesome Coding !! :)

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

Posted by: Gopesh9 on: 8/21/2012 [Member] Starter | Points: 25

Up
0
Down
@Vasanth

Yeah, its true.....

G. S.
.Net Developer

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

Login to post response