0

Is that possible to change the textbox text in the client side with c# script(Not javascript). Here is what I tried, but it doesn't work:

<asp:TextBox ID="Dis" runat="server">Old text</asp:TextBox>

<%Dis.Text = "New Text"; %>
5
  • C# executes at server. You must use JS to do anything in the client side. Commented May 19, 2014 at 13:45
  • @Fals I know how to do it with JS, I wrote some C# script at the client side, it works, but changing the textbox text doesn't work. Commented May 19, 2014 at 13:48
  • @ZhenxiaoHao as I have written in my ansewr the C# code is executed on the server and then the resulting html page goes to the client's web browser. That being said, you can't have execution of C# code in client side. Commented May 19, 2014 at 13:51
  • @ZhenxiaoHao You're confusing your concepts here. What you did was write it on the aspx page. This does not mean you wrote it "client-side". It will still execute on the server. Commented May 19, 2014 at 13:52
  • @Ben Black Alright, now I'm clear, thanks. Commented May 19, 2014 at 13:53

2 Answers 2

2

No it's not possible. C# is used for writing the server side code in web applications -when we have to do with web apps. I point out this because C# can be used to build almost everything. Whatever has to do with the client, you have to programm it in plain javascript or using a javascript framework. As far as how you will change the text of your textbox, it depends on when you want to do so. I mean which will be the event, which will trigger this change. If you specify this, I could post here some code to show you how you can achieve this.

UPDATE

When you refer to C# script, you possibly refer to the C# code we sometimes write inside our html pages using <% %>. Yeah, in this respect you can say that C# scripts exist. However, this code runs at the server, and then the created html page goes from the server to the client.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay, thanks, but there do exist C# script, right?
Yes, C# script exists, but it is not a web scripting technology like javascript. It is a desktop scripting language like batch or vb-script. For reference: csscript.net
1

Only using ajax request which is clearly not your requirement.

1 Comment

Is it possible to do it with ajax?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.