html - C# Web Page. Trouble using button click to update textbox -
So I'm just making a dummy webpage for the basics. Goal: On a button click, I want to update the information shown in the text box.
The method takes in the parameters of myButton_Click button how can I get an object to a text box (or an object for that matter) because this button is not being accessed with the event? I established a public variable, myTextBox _
, which I think I can edit freely again
HTML:
& Lt; Form, but I'm still not sure how to set myTextBox _
to understand it. Id = "form1" runat = "server" & gt; & Lt; P style = "height: 324px" & gt; & Lt; Asp: button id = "mybutton" runat = "server" enabledTheming = "true" text = "button" onclick = "myButton_Click" /> & Lt; ASP: Text Box ID = "MyTextbox" runs = "Server" & gt; Hello & lt; / Asp: text box & gt; & Lt; / P & gt; & Lt; / Form & gt;
Then the C # code:
textbox myTextBox_; Protected Zero Page_Load (Object Sender, EventArgues E) {// Perhaps the initialization code myTextBox_ is set to id on myTextbox, but how? } Protected Zero myButton_Click (Object Sender, EventArgs e) {myTextbox_.text = "Bye"; }
You are very close, all you have to do:
protected myButton_Click (Object Sender, EventArgs e) {myTextBox.Text = "Bye"; }
You do not need to set up anything in the Page_Load
method, as you set them as runatserver
That's why they are accessible from the back codes.
As already mentioned, a postback will be required to work on this, do not use this AJAX or in pure JavaScript.
Comments
Post a Comment