Click here to Skip to main content
15,896,259 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

We've one text box (asp:textbox) and a button (asp:button type=image) in asp.net page.
The below javascript function has been called on OnClientClick of the button.

document.getElementById("txtID").value="";

or

document.getElementById("<%=txtID.ClientID%>").value="";


This results in it clearing the value in text box, but, when post back, the value of the text box it not cleared.

When I validate in code behind like;
If(txtID.Text <> "")
{
   .....
}

it executes the lines inside the if statement.

We are using VS 2008, .Net Framework 2.0 and the controls are placed inside update panel.

If anybody have an idea please help us to overcome this issue.

Thanks,
Rishi
Posted
Updated 10-Nov-10 21:47pm
v2
Comments
Dalek Dave 11-Nov-10 3:47am    
Edited for Readability, Code Block and Syntax.

Add trigger for Update Panel (try it once)

XML
<ajax:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
-- Your Content Here.
</ContentTemplate>
<Triggers><ajax:AsyncPostBackTrigger ControlID="btnId" </Triggers>
</ajax:UpdatePanel>
 
Share this answer
 
Comments
Dalek Dave 11-Nov-10 3:48am    
Good Call.
Hi,


If you are using Ajax controls, why it is going to postback?
Is there any upload functionality in that screen?

Do the following thing.
1.Add the button id to Update panel as Triggers.
2.Enable ChildTriggers property as True.


Regards,
Kiran.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900