Note: I'm just an lowly intern here, so be nice :) I've spent some time researching before asking but didn't find the answer I'm looking for.
Suppose I have a line in my .aspx file like so:
<asp:HiddenField runat="server" ID="hiddenfield" Value=??? >
What should I put for the value if I would like this hidden field to display a .png image when shown?
Sorry I can't give much more detail, I don't want to violate my company's policies. If you need any more information, let me know and I'll try to give an example.
If you want to display an image, you should use the Image control.
If you want to hide it, wrap it in a div and set the visibility to hidden. For example:
<div id="divHidden" style="visibility: hidden">
<asp:Image runat="server" AlternateText="this is an image" ImageUrl="/img/myimage.gif"/>
</div>
May be you can save image path only in hidden field using this.
<asp:HiddenField runat="server" ID="hiddenfield" Value="/img/myimage.png" >
And later retrieve that using javscript document.getElementById("hiddenfield").value , and set that path to actual img element if needed.
You probably want to use:
<asp:Image ID="myImage" ImageUrl="myimage.png" Visible="false" AlternateText="foo" />
And when you need to show it from your codeBehind:
myImage.Visible=true;
Related
I am currently trying to have a bizform as part of my transformation as:
<cms:BizForm runat="server" ID="BizForm" FormName="YourBizFormCodeName" EnableViewState="false" FormDisplayText="Form submitted"/>
In the DocumentType/PageType I have a field that allows the user to enter whatever they want to display once the form has been submitted, so in theory I need to go about and change FormDisplayText to what has been provided.
I have tried using Eval("SubmitText") inside FormDisplayText, but it doesn't work.
Does anyone have a solution for this?
Thank you
Following code works fine for me (Kentico v8.1):
<cms:BizForm runat="server" ID="BizForm" FormName="test" EnableViewState="false"
FormDisplayText='<%# CMS.MacroEngine.MacroContext.CurrentResolver.ResolveMacros("{%CurrentDocument.SubmitText#%}") %>' />
I declared an picture in my ASP.NET and set it to hidden by default with style="visbility:hidden;". Is there anyway to access this image from the C# and change its visibility? Here is the img line from the ASP.NET:
<img src="canoe.png" alt="Boat Trailer" height="350px" width="600px" id="canoe" style="float:right; margin-right: 100px; visibility:hidden;" />
Use ASP:Image instead.
<ASP:Image id="myImage" Visibile="False" ImgUrl="link" runat="server">
Then you can access it in the backend with:
myImage.Visible = true;
If it is just server side to control the image visibility, just use,
<asp:Image ID="Image1" runat="server" Visible="false" />
You'll need to make this into a server tag first by adding runat='server' and an id. Then you can change its properties before the page loads like so:
<IMG ID>.Style["visibility"] = "visible";
replacing with the ID of your element.
Note about other answers: C# Visibility property will not change the CSS visibility but will actually remove or add the element, if you simply change that while the element is still set to visibility: hidden then it will still not be visible
Discalimer, this is an untested solution, you may have to check the syntax on the use of the Style property
Option 1
You can change it on the server side by adding an ID attribute and runat='server'.
Option 2
You can use an ASP.NET Image control and apply your changes there.
<asp:Image id="myimg" runat='server'.../>
HOWEVER, if you go with this option, you should still use CSS/Javascript to show/hide your image since setting Visible='false' on a server side control will prevent the HTML from rendering altogether which I doubt is the output your are expecting.
If you are performing this logic on the server side, why do you need to render the image as hidden? If you are showing the image based on user input then you should do it on client side Javascript.
I have a multiline checkbox. I want to use RadSpell.
But everytime I insert text on the textbox it doesn't display red lines.
How can i do this?
here is my code.
<telerik:RadTextBox ID="textbox1" runat="server" TextMode="MultiLine" Rows="4"
Columns="51" Width="401px" Font-Size="10" Font-Names="Calibri" />
<telerik:radspell id="RadSpell1" runat="server" DictionaryLanguage="English"
controltocheck="textbox1" spellcheckprovider="PhoneticProvider"
supportedlanguages="en-US,English" ButtonType="None"/>
NOTE: No buttons needed.
I just want to show all the words that are misspelled.
That's a browser feature - inline spellchecking. All modern browsers have it. Well, IE doesn't, but why should we call it modern? ;-)
What RadSpell can do for you is a popup with suggestions and information.
EDIT: Forgot to mention you can trigger RadSpell's check programmatically: http://www.telerik.com/help/aspnet-ajax/spell-client-side-api.html. Look for the startSpellCheck() method. For example in the onblur event.
i have an asp.net webform. the users enter data into the textboxes and i do OnClick="SubmitData" with a button:
now i would like to use jquery and make my form look much better and i do not know if i can keep the asp.net controls or whether i have to convert to html controls.
question do i need to convert
<asp:TextBox ID="section_c_issue_error_identified_byTextBox" width="500" runat="server"
/>
to something like this:
<textarea name="comments" id="comments" rows="5" cols="60"></textarea>
and if so, how would i grab the user input from these new html textboxes?
can you tell me exactly how would i pass these values into my c# code?
You don't need to convert anything as it gets converted to html anyway on clientside.
There are few ways to grab the value of the text box such as,
If the following is my textbox,
<asp:TextBox ID="txtCountry" Width="500" runat="server" CssClass="countryText" />
I can use,
$('#<%= txtCountry.ClientID%>').val()
$('.countryText').val()
You don't need to convert anything, simply adding the property clientID the type static
ClientIDMode="Static"
That's warranted that the id asp component doesn't change the name of the id
<asp:TextBox ID="txtCountry" Width="500" runat="server" CssClass="countryText" ClientIDMode="Static" />
$('#txtCountry').val();
question do i need to convert
<asp:TextBox ID="section_c_issue_error_identified_byTextBox"
width="500" runat="server"
/>
to something like this:
<textarea name="comments" id="comments" rows="5"
cols="60">
Yes, you need to do that.
To capture input from those controls using JQuery, you need to do:
var elementValue = $('#elementid').val();
elementid is the id you assigned to the element in your markup. In your example above, it would be "comments".
elementValue will have the text entered in your text area.
Say I have a dynamically generated LinkButton in my ascx.cs code-behind. How could I go about "printing" this control to my page? Obviously I can't do something like just print the Text property as I need the button to retain its hyperlink. I'm guessing I want to use the WebControl.Render method, but I'm not familiar with it at all and haven't been able to find a good example of its use.
This article http://www.tomot.de/en-us/article/3/asp.net/create-a-control-in-the-codebehind-and-retrieve-its-rendered-output should explain the basics of what you are looking for.
You could provide a label at the right location in the page: <asp:Label id="myLinkButtonPlace" runat="server"></asp:Label>, and in code, you could add the linkbutton to the controlcollection of the label: this.myLinkButtonPlace.Controls.Add(aLinkButton);
Following on from #Joachim VR, there are many other asp.net controls with which you can add a dynamically created control to.
<asp:Label id="Label1" runat="server" />
<asp:PlaceHolder id="Placeholder1" runat="server" />
<asp:Panel id="Panel1" runat="server" />
The above would render HTML different.
So the Label would render as a <span id="Label1"><a></a></span>
Panel as <div id="Placeholder1"><a></a></div>
The Placeholder would simply render as the <a></a>