Clear textbox after function call

Posted by Rohanleuva under C# on 4/17/2013 | Points: 10 | Views : 1307 | Status : [Member] | Replies : 9
Hello everyone,
I am calling function for generating excel on click event of button.It works fine and generating the desired output.But,i have one text box on the page,i want to clear it after generating the excel.it is preserving the values even after the excel generation. I tried string.empty after function call but it did not worked. I want to know about the way how to forcefully clear the text box at certain time?Any help would be greatly appreciated.




Responses

Posted by: Learningtorise on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
I think you need to share your function code to get idea where you are clearing textbox.. and find cause for same..

You can write a javascript function to clear your textbox in page and call it from code behind file using
ClientScriptManager.RegisterClientScriptBlock, after creating Excel File.


http://hashtagakash.wordpress.com/

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

Posted by: Rohanleuva on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
I am calling excel() in button1_click(). after call to excel i am trying textbox1.text=string.empty; its not working,why?Thats so ugly. Further,how to implement the way you suggested?

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

Posted by: Learningtorise on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
Try textbox1.text = "";
R u Using ASP.Net ?

Create a javarcipt function something like this:
function A(){
alert(document.getElementByID("textbox1.text"));
document.getElementByID("textbox1.text").value = '';
}

Write one line code after Excel() in your function to call that javascript Method

ClientScript.RegisterOnSubmitStatement(this.GetType(), "ConfirmSubmit", "A();");

http://hashtagakash.wordpress.com/

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

Posted by: Rohanleuva on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
i am working with web application.The above code also doesnt work.
This one is the click event of the button:

protected void Button1_Click(object sender, EventArgs e)
{
GenerateExcel(GridView2);
ClientScript.RegisterOnSubmitStatement(this.GetType(), "ConfirmSubmit", "A();");
}

Implemented code in the head of the page as javascript:

<script type="text/javascript">
function A() {
alert(document.getElementByID("TextBox1.text"));
document.getElementByID("TextBox1.text").value = '';
}

</script>

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

Posted by: Learningtorise on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
Try ClientScript.RegisterStartUpScript

if this does not work then
ClientScript.RegisterScriptBlock

http://hashtagakash.wordpress.com/

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

Posted by: Rohanleuva on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
None of the implementations worked...I am not able to figure out the problem....Why the textbox is preserving the values even after the string.empty command. It means that,this command doesnt affect the state(value) of the textbox,want someone to answer it...WHY?

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

Posted by: Learningtorise on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
Check Whether you have assign any value to TextBox on Page_Load Event...

http://hashtagakash.wordpress.com/

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

Posted by: Rohanleuva on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
not at all.......never assigned any value to the textbox in whole project....

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

Posted by: lakhansin-22735 on: 7/14/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

Here, you have to clear your textbox using PreRender event, try the below code
protected void Page_PreRender(object sender, EventArgs e)

{
textbox1.text = string.Empty;
}

Thanks

Lakhan Singh
Tech Lead
BeyondKey System Pvt. Ltd.
Indore, M.P.
India

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

Login to post response