If i enter below text in my multi line textbox
Nitin
Kumar
Shukla
then i got this result
Nitin Kumar Shukla
but i want result same as i write in my multi line textbox
Here is my aspx page code
<asp:TextBox ID="ttt" TextMode="MultiLine" runat="server"></asp:TextBox>
<asp:Button ID="btn" runat="server" Text="hjhj" onclick="btn_Click" />
<asp:Label ID="lll" runat="server"></asp:Label>
here is my cs page code
protected void btn_Click(object sender, EventArgs e)
{
lll.Text = ttt.Text;
}
try this
lll.Text = ttt.Text.Replace(Environment.NewLine, "<br />");
Related
I have calculated the two textbox values and displayed successfully it into third textbox but the issues are when I enter value to textbox1 and move to textbox2 the page get reload as I have mentioned AutoPostBack="true" for textbox1 and textbox2 and when I remove this AutoPostBack="true" the calculated value is not displayed in third textbox.
Here is my code behind
protected void txttotal_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txttotal.Text) && !string.IsNullOrEmpty(txtdiscount.Text))
txtgrandtotal.Text = (Convert.ToInt32(txttotal.Text) - Convert.ToInt32(txtdiscount.Text)).ToString();
}
protected void txtdiscount_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txttotal.Text) && !string.IsNullOrEmpty(txtdiscount.Text))
txtgrandtotal.Text = (Convert.ToInt32(txttotal.Text) - Convert.ToInt32(txtdiscount.Text)).ToString();
}
Here is aspx code
<asp:TextBox ID="txttotal" runat="server" CssClass="textstyle" OnTextChanged="txttotal_TextChanged" AutoPostBack="true"></asp:TextBox>
<asp:TextBox ID="txtdiscount" runat="server" CssClass="textstyle" OnTextChanged="txtdiscount_TextChanged" AutoPostBack="true"></asp:TextBox>
<asp:TextBox ID="txtgrandtotal" runat="server" CssClass="textstyle" ReadOnly="true"></asp:TextBox>
To add the two text box value and show it on third text box you can add them on button click event here is the code
aspx page
<div>
<asp:TextBox runat="server" ID="txt1"></asp:TextBox>
<asp:TextBox runat="server" ID="txt2"></asp:TextBox>
<br />
<asp:Label runat="server" Text="Answer"></asp:Label> <asp:TextBox runat="server" ID="txt3"></asp:TextBox>
<asp:Button runat="server" ID="btn1" Text="CLICK TO ADD" OnClick="btn1_Click"/>
</div>
.cs
protected void btn1_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txt1.Text) && !string.IsNullOrEmpty(txt2.Text))
{
txt3.Text = (Convert.ToInt32(txt1.Text) + Convert.ToInt32(txt2.Text)).ToString();
}
else {
Response.Write("Please Enter Value");
}
}
I've got default.aspx/default.aspx.cs and other.cs where i "store" a bunch of functions.
In my default.aspx i've :
<asp:ImageButton ID="ImageButton1" CssClass="btn_img" ImageUrl="./images/1.png" runat="server" OnClick='<%# "setFunction(" +Eval("aGUID") +")" %>' />
in my default.aspx.cs
protected void setFunction(object sender, ImageClickEventArgs e)
{
string istr = e.ToString();
var iguid = new Guid(istr);
// this are classes/functions stored in other.cs
ManageFun mfun = new ManageFun();
mfun.setMM(iguid);
}
I though i was doing all right, but can't figure out what i'm doing wrong!
In matter of fact it does nothing!
Apreciate any help!
Thanks!
You can try this
<h3>ImageButton Sample</h3>
Click anywhere on the image.<br /><br />
<asp:ImageButton id="imagebutton1" runat="server"
AlternateText="ImageButton 1"
ImageAlign="left"
ImageUrl="images/pict.jpg"
OnClick="ImageButton_Click"/>
<br /><br />
<asp:label id="Label1" runat="server"/>
and C# code
public void ImageButton_Click(object sender, ImageClickEventArgs e)
{
Label1.Text = "You clicked the ImageButton control at the coordinates: (" +
e.X.ToString() + ", " + e.Y.ToString() + ")";
}
No need to write these <%#
Here is the reference Click
Basically asp:ImageButton with Onclick which will not call the server side code with Eval.
Edit:
You can directly call like this :
<asp:ImageButton ID="ImageButton1" CssClass="btn_img" ImageUrl="./images/1.png" runat="server" OnClick="setFunction" />
if you want to pass the parameter to that function you can assign the param to the CommandArguement as below
CommandArguement='<%# Eval("aGUID") %>'
in your SetFunction you can retrieve like this
string val = e.CommandArguement.ToString()
This is my .aspx code:
<asp:LinkButton ID="link" runat="server"> <telerik:RadToolTipManager
ID="toottip" runat="server" AutoTooltipify="true" Width="200px"
RelativeTo="Element" HideEvent="LeaveTargetAndToolTip"
WebServiceSettings-UseHttpGet="false" Animation="Fade"
EnableTheming="true" Title="Documents" ShowEvent="OnMouseOver">
<WebServiceSettings Method="GetToolTipData"
Path="InvestmentDropDownWebService.asmx" UseHttpGet="true"/>
<TargetControls>
<telerik:ToolTipTargetControl TargetControlID="link"></telerik:ToolTipTargetControl>
</TargetControls> </telerik:RadToolTipManager> </asp:LinkButton>
And this is the code behind:
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = getName();
link.Text = dt.Rows[0][Name].ToString();
}
I am trying this code but the problem is that on mouseover, the webservice is not called. If I set link button Text in .aspx page it's working fine...
How to solve it if the text is from codebehind?
did you tried by using by giving empty text in aspx page like
<asp:LinkButton ID="link" runat="server" Text=" "> <telerik:RadToolTipManager
ID="toottip" runat="server" AutoTooltipify="true" Width="200px"
RelativeTo="Element" HideEvent="LeaveTargetAndToolTip"
WebServiceSettings-UseHttpGet="false" Animation="Fade"
EnableTheming="true" Title="Documents" ShowEvent="OnMouseOver">
<WebServiceSettings Method="GetToolTipData"
Path="InvestmentDropDownWebService.asmx" UseHttpGet="true"/>
<TargetControls>
<telerik:ToolTipTargetControl TargetControlID="link"></telerik:ToolTipTargetControl>
</TargetControls> </telerik:RadToolTipManager> </asp:LinkButton>
I have 2 labels and 2 text boxes and 1 buttons displayed.
When the page loads the Name and Button (will be initially displayed). Later when i click on the Button i need to display the age label and textbox. How can i do this ?
<ol>
<li>
<asp:Label runat="server" AssociatedControlID="Name">
User name
</asp:Label>
<asp:TextBox runat="server" ID="Name" Width="167px" />
<asp:Button ID="Button1" runat="server" Text="Button" />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="age">age</asp:Label>
<asp:TextBox runat="server" ID="age" TextMode="age" Width="240px" />
</li>
</ol>
code for button press
protected void Button1_Click(object sender, EventArgs e)
{
}
You could set the label/textbox Visible property to True in server side. Alternatively, you could use JavaScript to avoid post backs to the server.
Add OnClientClick to your button :
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ShowLabel();"/>
and declare the JavaScript function on page:
<script type="text/javascript">
function ShowLabel() {
// Note that the client ID might be different from the server side ID
document.getElementById('lblAge').style.display = 'inherit';
}
</script>
You need to set the Label Display style to none initially.
<asp:Label ID="lblAge" style="display: none;" runat="server" AssociatedControlID="age">age</asp:Label>
Try below code:
You need to set Visible property of controls to True or False according to your requirement. By default, all controls are visible on the screen whenever they are added on the page.You need to do following thing:
You need to remove TextMode="age" as there is not any supported textmode of type age.
Need to define id of control if you want to access a control server side in code behind. So define the ID of Label that you put corresponding to Age textbox.
By Default age label and textbox will not be visible by using below code:
<asp:Label ID="lblAge" runat="server" AssociatedControlID="age" Visible="false">age</asp:Label>
<asp:TextBox runat="server" ID="age" Width="240px" Visible="false"/>
Code behind:
After button click age label and the textbox will be visible by using below code:
protected void Button1_Click(object sender, EventArgs e)
{
lblAge.Visible = true;
age.Visible = true;
}
First add id to elements and set visible false
<asp:Label runat="server" AssociatedControlID="age" Visible="false" Id="lbl1">age</asp:Label>
<asp:TextBox runat="server" ID="age" TextMode="age" Width="240px" Visible="false" />
button click event set visible true
protected void Button1_Click(object sender, EventArgs e)
{
lbl1.Visible = True;
age.Visible = True;
}
this is the basic concept of asp.net. you can use visible property of the control.
your TextMode enumeration is wrong. there is no Age enumeration for Textbox.TextMode TextMode
<li>
<asp:Label runat="server" AssociatedControlID="age" id="lblAge">age</asp:Label>
<asp:TextBox runat="server" ID="age" TextMode="age" Width="240px" />
</li>
in code behind
protected void Button1_Click(object sender, EventArgs e)
{
lblAge.Visible=true;
age.Visible=true;
}
protected void Page_Load(object sender, EventArgs e)
{
NameLabel.Visible = false;
NameBox.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
NameLabel.Visible = true;
NameBox.Visible = true;
}
I have one label and textbox1 and textbox2 and one button . I enter the text in textbox1
then click the button and how to show that textbox1 value in textbox2?
Add a click eventHandler to your button and set the text property of textbox2
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
Within your code file ...
protected void Button1_Click(object sender, EventArgs e)
{
TextBox2.Text = TextBox1.Text;
}
this.textbox2.Text = this.textbox1.Text;
in your button click add this code
textbox2.Text = textbox1.Text;
Double click the button. This will get you into codebehind text. After this write
textBox1.Text = textBox2.Text;
void Button1_Click(object sender, eventargs e)
{
TextBox1.Text = TextBox2.Text;
}