how can i add text to a legend from code behind
Assuming you're talking about the HTML Legend Tag and using C# in an ASP.NET site. You can give it an ID and a runat="server" then you can access it from the code behind by name and change its text property.
<form id="form1" runat="server">
<fieldset>
<legend id="myLegend" runat="server">Personalia:</legend>
Name: <input type="text" size="30" /><br />
Email: <input type="text" size="30" /><br />
Date of birth: <input type="text" size="10" />
</fieldset>
</form>
Then in the code behind:
myLegend.InnerText = "Foo";
Related
yes, I know this is basic, but how do I change the background colour of my razor web application from razor? Also, how would I change text colour in the web application too? If this has already been asked and answered before, I apologise. Please link that QA to me so I and future confused programmers will know where to look. Please forgive me for my stupidity. Here is the code:
#page
#model IndexModel
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>~Web APP to C# Form~</p>
</div>
<!--<form method="post">
<label>First Name: </label>
<input type="text" name="firstname">
<br />
<label>Last Name: </label>
<input type="text" name="lastname">
<br />
<label>Email Address: </label>
<input type="email" name="emailAddress">
<br />
<br />
<input type="submit">
</form>
-->
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"></script>
<form asp-controller="Index" method="post">
Enter Ticket Number:
#Html.TextBox("ticketnumber")
<br />
<button type="submit">Submit</button>
<br />
----------------------------------------------------
<br />
Ticket Title:
#Model.ticketTitle
<br />
<br />
Ticket Description:
#Model.ticketDescription
</form>
<body style="background-color:green">
Answer solved by Chetan Ranpariya.
How can I handle novalidate on client side, with having access to behind code
<form runat="server">
<form novalidate>
<label>Old Password</label>
<input type="password" class="form-control" required placeholder="Old Password" data-validation-required-message="This old password field is required">
</div>
<asp:Button ID="btnSave1" runat="server" Text="Save 1" OnClick="btnSave1Click" />
</form>
<form novalidate>
<label>name</label>
<input type="text" class="form-control" required placeholder="Name" data-validation-required-message="Name is required">
</div>
<asp:Button ID="btnSave2" runat="server" Text="Save 2" OnClick="btnSave2Click" />
</form>
</form>
For now button click doesn't work. I try to provide some change on buttons, so:
<asp:Button ID="btnSave1" style="display:none" runat="server" Text="Save 1" OnClick="btnSave1Click" />
<input type='button' class="button" value='ثبت تغییرات' style="cursor: pointer; width: 150px" onclick='save1();'/>
<script>
function save1() {
document.getElementById("btnSave1").click();
}
</script>
On this case only "PostBack" works and "btnSave1Click" event doesn't work.
I'm trying to use code behind to read text from HTML provided to me. After researching this topic I found that almost all instances of this involve Web Forms controls(asp:) for the textboxes but the HTML I was given does not, but instead is:
<p>
<label>Address</label>
<textarea class="w3-input w3-border" name="addr" cols="30" rows="4"></textarea>
</p>
<div class="w3-half w3-container">
<p>
<label>Phone:</label>
<input type="text" class="w3-input"/>
</div>
<div class="w3-half w3-container">
<label style="padding-left:10px;">Email:</label>
<input type="text" class="w3-input"/>
</div>
</p>
Will I still be able to read the user-provided text from these boxes or will I need to alter the HTML?
A couple of my unsuccessful code-behind attempts to extract the address supplied:
string address = ((textarea)Address.FindControl("addr")).Text;
string address = ((TextBox)Address.FindControl("addr")).Text;
Update:
Using the server control described in a solution offered, I get an error message stating that "A page can have only one server-side Form tag."
This results from the following markup:
<form runat="server">
<asp:textbox id="addr" runat="server" textmode="multiline" />
</form>
followed later by:
<form runat="server">
<asp:Button ID="Ship" runat="server" Text="Ship" OnClick="Ship_Click" style="padding: 10px; margin-bottom: 10px;" class="w3-round w3-blue" />
<asp:Button ID="Rate" runat="server" Text="Rate" OnClick="Rate_Click" style="padding: 10px; margin-bottom: 10px;" class="w3-round w3-blue" />
</form>
The textarea is located in a different section than the buttons and I'm unclear on how to make both functional either without a form tag or without having them share the same one. Thanks
You need to use a server control if you're looking to access the value in code behind. Use an ASP TextBox and set the TextMode to MultiLine:
<asp:TextBox ID="textarea1" runat="server" TextMode="MultiLine" />
Then in code behind:
string addr = textarea1.Text;
UPDATE to demonstrate multiple forms on the same page:
<form ID="form1" runat="server">
<asp:Button ID="Ship" runat="server" Text="Ship" OnClick="Ship_Click" style="padding: 10px; margin-bottom: 10px;" class="w3-round w3-blue" />
<asp:Button ID="Rate" runat="server" Text="Rate" OnClick="Rate_Click" style="padding: 10px; margin-bottom: 10px;" class="w3-round w3-blue" />
</form>
<form id="form2" action="WebForm1.aspx" method="post">
<asp:TextBox ID="textarea1" runat="server" TextMode="MultiLine" />
</form>
From here, you can use either method of retrieving the textarea1 value in code behind for posts from form1 or form2...
form1:
string addr = textarea1.Text;
form2:
string addr = Request["textarea1"].ToString();
Add runat="server" to your TEXTAREA and INPUT tags. Then you can access them from code-behind. You also need to assign the ID attribute of each one.
<p>
<label>Address</label>
<textarea class="w3-input w3-border" name="addr" id="textarea1" runat="server" cols="30" rows="4"></textarea>
</p>
<div class="w3-half w3-container">
<p>
<label>Phone:</label>
<input type="text" class="w3-input" runat="server" id="input1" />
</div>
<div class="w3-half w3-container">
<label style="padding-left:10px;">Email:</label>
<input type="text" class="w3-input" runat="server" id="input2" />
</div>
</p>
People here wonder because its too old and already asked..
but here is my problem arises.
You see two input fields with same name?
HTML CODE
<html>
<head><title></title>
</head>
<body>
<input type="hidden" name="textbox" />
<form name="tax280" method="post">
<table>
<tr><td>
<input type="text" name="textbox" />
</td>
</tr>
</table>
<input type="submit" value="Register" />
</form>
</body>
</html>
But when i use below code. I think values gone set in hidden attribute.
HtmlDocument doc = this.webBrowser1.Document;
doc.GetElementById("textbox").SetAttribute("Value", "text");
In Simple How to set values required textbox alone i can't find any solution please help.
please visit this link and click link that page contains https://onlineservices.tin.egov-nsdl.com/etaxnew/tdsnontds.jsp
Well, you need to set an ID. Because GetElementById works with an id attribute, not name.
<input type="text" name="textbox" id="textbox" />
https://jsfiddle.net/vdpd02um/
If you have this HTML, please note the difference between id and name attributes:
<input type="text" name="textbox" id="firstTextbox" />
<input type="text" name="textbox" id="secondTextbox" />
You can access them via getElementsByName (ByName returns an array):
var fistTextBox = document.getElementsByName('textbox')[0];
var secondTextBox = document.getElementsByName('textbox')[1];
BUT to avoid problems you should use:
var fistTextBox = document.getElementById('firstTextbox');
var secondTextBox = document.getElementById('secondTextbox');
Because .getElementByIdreturn just one item.
After a day I found answer for my question.
when there is 2 or more text input fields its easy to fill data on both the fields.
<html>
<head>
<title></title>
</head>
<body>
<input type="hidden" name="textbox" />
<form name="tax280" method="post">
<table>
<tr>
<td>
<input type="text" name="textbox" />
</td>
</tr>
</table>
<input type="submit" value="Register" />
</form>
</body>
</html>
and windows form application code is below.
var elements = webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement element in elements)
{
if (element.Name.Contains("textbox"))
{
element.SetAttribute("Value", "my text");
}
}
it works but the problem is data fill in both the text field..
Thank you for the helping hearts those are replied for my problem.
:D
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" MasterPageFile="MasterPage.master" %>
<asp:Content ID="ContentPlaceHolder1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>
<asp:Content ID="ContentPlaceHolder2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<br />
<div id="signupform">
<form class="signupform" name="formreg" runat="server" onsubmit="return valform()"> <br/>
<input dir="rtl" type="text" name="uname" class="uname"/> </br>
<input dir="rtl" type="text" name="fname" class="fname"/> </br>
<input dir="rtl" type="text" name="lname" class="lname"/> </br>
<input dir="rtl" type="password" name="pword" class="pword"/> </br>
<input dir="rtl" type="password" name="rpword" class="rpword"/> </br>
<input dir="rtl" type="text" name="mmail" class="mail"/> </br>
<input dir="rtl" type="text" name="rmail" class="rmail"/> </br>
<input dir="rtl" type="text" name="gil" class="gil"/> </br>
<input type="checkbox" name="anon" value="True" class="dropan"/></br>
<input type="submit" name="sub" class="subbutton" value=""/>
<%=registrationstatus %>
</form>
</div>
</asp:Content>
This is my code, My problem is that the onsubmit="return valform()" attribute on my form wont fire if the runat="server" attribute exists, they can't work together please help me I am clueless why these two attributes wont work together
This is because you can't use both together. As said in the docs -
<input type="text" id="Textbox1" runat="server">
Doing this will give you programmatic access to the HTML element on the server before the Web page is created and sent down to the client. The HTML element must contain an id attribute. This attribute serves as an identity for the element and enables you to program to elements by their specific IDs. In addition to this attribute, the HTML element must contain runat="server". This tells the processing server that the tag is processed on the server and is not to be considered a traditional HTML element.
Here is the reference.
http://msdn.microsoft.com/en-us/library/aa478973.aspx
under section - Using HTML Server Controls
So, HTML with run='server' will not be treated as a normal Html element and thus will always be processed by the server. If you want to override the default behavior, you have to bind your javascripts with after the html is loaded in the browser, may be using jQuery or something similar. With jQuery something like this would help -
$(function(){
$("#formreg").submit(function(){
return valform();
});
});
By examing your code, I reach on conclusion that you might be using another form tag on Master page and there is no javascript issue. Only one form tag(Server Side) can exists either on a master page or content page. They can not be nested. When you would use runat="Server" attribute on both of form tags then error occurs saying "A page can have only one server-side Form tag". So remove runat="server" attribute from one of the form tags, onsubmit would begin firing.
I solved it with very easy way.
if we have such a form
<form method="post" name="setting-form" >
<input type="text" id="UserName" name="UserName" value=""
placeholder="user name" >
<input type="password" id="Password" name="password" value="" placeholder="password" >
<div id="remember" class="checkbox">
<label>remember me</label>
<asp:CheckBox ID="RememberMe" runat="server" />
</div>
<input type="submit" value="login" id="login-btn"/>
</form>
You can now catch get that event before the form postback and stop it from postback and do all the ajax you want using this jquery.
$(document).ready(function () {
$("#login-btn").click(function (event) {
event.preventDefault();
alert("do what ever you want");
});
});