Anyway to dynamically set text in an asp:FileUpload? - c#

When the user selects an item from a dropdownlist containing image names, I would like the FileUpload text box to be filled with a message I program such as "Replace this image with..." How would I do this?

Security restrictions in certain browsers (IE at least) prevent you from being able to actually set the text of an <input type="file" /> element, which is what the FileUpload ASP.NET control renders.
I am on a project where we are trying to manipulate the appearance of file upload elements, and it's proving to be quite difficult to do in a cross-browser-compliant manner. I suggest looking at flash-based solutions such as Uploadify, which is more customizable.

Due to the nature of the control, for security reasons you cannot manipulate it beyond some styling.
What you can do, however, is use a Flash or Silverlight based upload control. Or put your desired message in a label above the file input.

Not possible. The < input type="file" /> is part of the browser chrome. Some browsers don't show any text at all, so any solution would not be robust. As Bryan suggests, use a < label >.

Like others have said, there is no way to directly change the text of the file name box, but what you can do is create a label and use positioning to make sure the label appears directly above the uploader.
<span runat="server" id="SelectedFileSpan" style="position: absolute; top: 10px; left: 12px">
<asp:Label runat="server" ID="FileNameLabel"></asp:Label>
</span>
<asp:FileUpload runat="server" ID="FileUploader" />
Then set the text of the label.

Related

Change button text on ASPxPopupControl buttons

I am trying to change the text of ASPxPopupControl buttons (I have not written the ASPxPopupControl code myself. Those guys are long gone. :) So it's up to me). As far as I know, the ASPxPopupControl default buttons are used and if I want to change the button text I have to add code to the .aspx file. I have tried searching for an answer on the DevExpress docs and the world wide web. But could not find anything that matches my needs. I am very grateful for any ideas.
This is the buttons I am talking about:
The ASPxPopupControl code (There is an attempt to add a custom button but it does not work.):
<dxpc:ASPxPopupControl ID="someLongID" runat="server"
AllowDragging="True" ClientInstanceName="someLongID"
CloseAction="CloseButton" HeaderText="Varning!" Modal="True"
PopupHorizontalAlign="WindowCenter"
Width="300px">
<ContentCollection>
<dxpc:PopupControlContentControl ID="PopupControlContentControl3"
runat="server" Enabled="True">
<p>
<br />
</p>
<p align="right">
<input
id="Button1"
onclick="javascript:someLongID.Hide();"
type="button" value="Stäng" />
</p>
</dxpc:PopupControlContentControl>
</ContentCollection>
<HeaderStyle BackColor="#FFB6C1" />
</dxpc:ASPxPopupControl>
If you don't implement you own popup edit form, but use the built-in one, it is necessary to access the required text setting via the ASPxGridView.SettingsText (CommandUpdate, etc.).
I think you can change the text content in the item property (in "Properties") which is located in the right down corner on VS.
you can click on the item in "Design" mode and then check its setting in "Properties"
Hope this helps

Change the color of different lines in a textbox in codebehind?

I need to have have diffrent lines in different colors for a textbox.
I donot want to use a rictextbox.
<asp:TextBox ID="TxtMessage" runat="server" Width="550" TextMode="MultiLine" Height="242px" />
Is there any way to use some html to achieve this?
I have tried this but it doesnot work:
Txtmsg2.Text = "<span style='color: red;'>ENFIELD ONLY:</span>" & Chr(13)
This is not possible within a text area, you'll need to use a rich text box (which I see you don't want to use) or a WYSIWYG editor such as TinyMCE.

ASP.NET Rich Text Box gives error

Im working on a web app here in C# and I have a listview. When I do an edit on the listview everything works great. In my notes field its a textbox, Id rather have it larger like a Richtextbox, but when I put that in there I get an error, other than label or textbox I cant seem to do anything. How can I make the notes field more like a rich text box area for a end user to edit?
Notes:
<asp:TextBox ID="NotesTextBox" runat="server" Text='<%# Bind("Notes") %>' Width="700px" />
<br />
RichTextBox is a WinForms control. It does not work in the WebForms platform. If you want a "rich text" editor, you'll have to find a third-party component that allows this type of editing.

How to make a button not show up but still be used by javascript?

I am using a button that has to be invible and should be used by a javascript function.
<asp:Button ID ="btnDummy1" runat="server" Visible ="true" OnClick="btnSubmit1_Click" width="0px" height="0px"/
I cannot keep visible = false as it the javascript will not use invible content in the poage. I havetried to give width=0 and height=0, still it showws up in Chrome. What do you guys think i should do?
Thanks in advance :)
A pretty clean approach in ASP.Net it give it a "hidden" class:
<asp:Button ID ="btnDummy1" runat="server" CssClass="hidden" />
Then in your stylesheet:
.hidden { display: none; }
If you set it to Visible="False" then the code will not be executed.
Instead I think you should wrap it in a <div> and set display:none via css:
<div style="display: none;">
<asp:Button ID ="btnDummy1" runat="server" OnClick="btnSubmit1_Click" />
</div>
adding style="display:none" would hide the button till you make it visible again
<asp:Button ID ="btnDummy1" runat="server" OnClick="btnSubmit1_Click" style="display:none"/>
How about
style="display:none"
for the button instead of Visible = "true".
Can you just use a hidden form field in this case? This is generally the preferred method of passing information along.
See http://www.tizag.com/htmlT/htmlhidden.php
<asp:Button ID="btnMyOrders" runat="server" Text="my orders" CssClass="dropdown-item" OnClick="btnMyOrders_Click" Visible="False" />
Example then in Form(){
btn.Visible = true; to show it again
}
I think the first question you should ask yourself is : why would I put in my HTML doc a button that should not be visible ?
An HTML document should be used ONLY TO DESCRIBE A CONTENT'S SEMANTICS. So an HTML doc should ONLY contain the content you want to publish and extra data to explain the content's SEMANTIC !! NOTHING about the way it is displayed, NOTHING about the way it behaves !!
All displaying and behaviors questions should be managed with CSS and Javascript, NEVER within HTML itself.
Any element needed for Javascript only purpose should be added in the doc by Javascript itself !
You should never find, in an HTML doc, such things as prev/next buttons for a javascript picture gallery for example. The HTML doc should only contain the pictures list, than your JS script will change the way this list is shown, making it a eye candy gallery and add buttons for navigation.
So in your example, your saying you want to add in your HTML doc an invisible button with some Javascript actions on it.... that's probably an example of some content that should never be in the HTML doc.

Making text box hidden in ASP.NET

I am using ASP.NET 3.5 and C#.
On my page I need to have a Text box that must not be visible to the user but it MUST be there when you look at the Page Source, reason being, another program called Eloqua will be looking at the page source and it must get the value of that text box.
The value of that text box will be populated based on what the user selects.
Thus, I cant set the text box property to Visible = False because then it will not be in the source HTML and I can't set the Enabled = False because I do not want the user to see the text box.
Is there some property I can use to make this text box hidden to the user but still visible in the page source?
My ASP.NET text box
<asp:TextBox ID="txtTester" runat="server"></asp:TextBox>
You can use a hidden field.
<asp:HiddenField id="myHiddenInput" runat="server" />
Use it just like a textbox.
Try this to invisible textbox instead of server side Visible property :
myTextBox.Style.Add("visibility", "hidden");
// or :
myTextBox.Style.Add("display", "none");
First thought: Can you use a hidden field? This would be much more suitable (<asp:hiddenfield ID="blah" runat="Server" /> if you want a .NET control).
If the app won't take that though you can actually just put "style='display: none;'" in the code-infront of the page. Intellisense won't like it, but it'll render just fine (EG: <asp:TextBox id="txtField" style="display: none;" runat="server" />)
Also from the codebehind you can do txtField.Attributes.Add("style", "display: none");
Or you could also just give it a CssClass "hidden" which in your CSS is defined as ".hidden { display: none;}"
The CSS class or just using a hidden field would be my recommendations.
Page.RegisterHiddenField or asp:HiddenField
CSS:
.hidden-div
{
display: none;
}
HTML:
<div class="hidden-div">
<input ... />
</div>
It will cause your input to be hidden, but it's gonna be visible in source code.
EDIT: Sorry, I misread it. I thought you wanted to hide an input. But it doesn't matter anyway, just replace input with basically anything.
If it must be a textbox for whatever reason just hide it with css:
<input type="text" name="blah" style="display:none" />
By Setting Visible = "false" in server side will not render the control. You should either use asp:Hidden or INPUT type="hidden". Other option is using CSS, by setting display:none.
Why not use a hidden field:
<input type="hidden" name="blah" />
How about using CSS to hide a div containing the text box:
.hidden {
position: absolute;
left: -9999px;
}
Then within your page:
<div class="hidden">
<asp:TextBox ID="TextBox1" runat="server" Text="hi"></asp:TextBox>
</div>
Hope this helps.
Simply, Try to create a CSS class and attach it to your TextBox as the following:
CSS Class Style
<style>
.Hide {
display:none;
}
</style>
Textbox using CssClass="Hide"
<asp:TextBox ID="txtTester" runat="server" CssClass="Hide"></asp:TextBox>
Note: you can't use validation with the Hidden control
<asp:TextBox ID="TextBox2" runat="server" visible="false"></asp:TextBox>

Categories

Resources