Hello I'm having trouble getting the AjaxFileUpload control to work properly. I have it working properly on a different page, using identical code, but not inside of a panel on this page. It functions properly and allows me to select files and hits the 'OnUploadComplete' function, however it is crashing on the .SaveAs giving me NullReferenceException. I put the ghostupload control at the start of the page at the recommendation after finding others with similar problems and this is necessary or the control doesn't work at all.
aspx code (outside panel)
<div style="display:none"> <AjaxControlToolkit:AjaxFileUpload ID="ghostAjaxFileUpload" runat="server" OnUploadComplete="AjaxFileUpload_UploadComplete" /></div>
aspx code (inside panel)
<AjaxControlToolkit:AjaxFileUpload ID="ajaxupload1" runat="server" ThrobberID="loader123" AllowedFileTypes="jpg,jpeg" MaximumNumberOfFiles="2" OnUploadComplete="AjaxFileUpload_UploadComplete" /><asp:Image id="loader123" ImageUrl="images/loading.gif" Style="display:None" runat="server" />
aspx.cs code
protected void AjaxFileUpload_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
//...other logic/file checking (working fine)
ajaxupload1.SaveAs(appSession.GlobalImageFolder + appSession.GlobalProductImageFolder + filename);
}
Been working on this one all day and it's got me stumped! I really like the AjaxFileUpload so I'm hoping I won't have to resort to a different upload control. Really appreciate any help on this one!
Cheers,
Jordan
Related
I have a C# application that uses WebForm. I am using the WebForm to display my application content (HTML / JavaScript).
My question is how do I communicate between them (API)?
Example: I like to minimize the program by using HTML buttons, etc....
If you have a web browser control on top of a normal control you could use the navigation event. E.g. make a link like:
Minimize
And in the navigation event of the browser control (I don't know how the event is actually called - just an example):
public void browser_OnNavigate(object sender, NavigateArgs e)
{
if (e.Target == "#MinimizeWindow")
// minimize and cancel event
else
// navigate to target
}
Local or Remote WebForms Application
You can use AJAX if you are trying to communicate with an external (or local) application.
Local WebForms Application
If by "application" you are actually referring to the back-end (code-behinds, etc.) of your WebForms project, then the other thing to look into are "server tags," otherwise known as "bee-stings." Here are just a few exsamples:
<% %>
<%-- --%>
<%# %>
<%= %>
Additionally, you can use event handlers for things like server-side button or anchor clicks, dropdownlist value changes, etc. You can make standard HTML controls server-side by adding the runat="server" attribute, or you can use .NET's WebControls (though they will still have to have the runat="server" attribute). Examples of these would be:
Front End
<button runat="server" onserverclick="btn_click">Click me</button>
...
or
...
<asp:Button runat="server" OnClick="btn_click">Click me</asp:Button>
Back End
protected void btn_click(object sender, EventArgs e)
{
...
}
I'm trying to add a button to the webpage, from the code behind. I have a single empty div on my main page that visible on and off, when needed. However the content I wish to create dynamically as the div content can change dependent on conditions.
I have realised that within my ASP Control I use a / (backslash) which cancels out my HTML. The problem I now have is understanding how I can get around this with code, is there a way to add ASP Controls to the web page? I am open to suggestions outside of the InnerHtml.
I'm creating my Button like so (in my Code Behind):
string buttonout = string.Format("<asp:Button ID=\"helpButton_0\" CommandArgument=\"0\" CssClass=\"HelpButton\" runat=\"server\" Text=\"?\"/>");
innercontent[0] = string.Format("<table><tr><td>Lead Passenger Information</td></tr><tr><td>Here by deafaul we used your detaisl from your profile, if you're not the lead passenger (As in you're booking for someone else) then please change details.</td></tr><tr><td>{0}</td></tr></table>"+ buttonout);
As Said above, The reason this doesn't work is because of InnerHtml hating backslashes, I think.
I do have a solution to this; and that's by adding more divs to the page.
<div id="HelpBoxDiv" runat="server" Visible="false">
<div id="HelpBoxDiv_Top" runat="server" Visible="true">
</div>
<div id="HelpBoxDiv_Bottom" runat="server" Visible="true">
<asp:Button ID="button_HelpBox_false" runat="server" />
</div>
</div>
I would then add my Innerhtml to the _Top Div, instead of the HelpBoxDiv which I am currently doing now. However this solution doesn't teach me anything.
I am hesitant to ask questions here, as I know a lot of question have been asked and I am sure this one has before, but I didn't find a solution. Any help is much appreciated.
Thank you.
I have realised that within my ASP Control I use a / (backslash) which
cancels out my HTML. The problem I now have is understanding how I can
get around this with code, is there a way to add ASP Controls to the
web page? I am open to suggestions outside of the InnerHtml.
You cannot add ASP.Net server control like a literal string.
Instead, you want to add the dynamic server control to the following approach -
ASPX
<asp:PlaceHolder runat="server" ID="PlaceHolder1"></asp:PlaceHolder>
Code Behind
protected void Page_Init(object sender, EventArgs e)
{
var button = new Button
{
ID = "helpButton_0",
CommandArgument = "0",
CssClass = "HelpButton",
Text = "?"
};
button.Command += button_Command;
PlaceHolder1.Controls.Add(button);
}
private void button_Command(object sender, CommandEventArgs e)
{
// Handle dynamic button's command event.
}
I have a Webpart that contains a couple of dropdowns on an update panel. There is a submit button that has the PostBackUrl set to a sharepoint Application Page
<asp:DropDownList ID="ClassSelector" runat="server" Enabled="False"
AutoPostBack="True" onselectedindexchanged="ClassSelector_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="-null-">Select Class...</asp:ListItem>
<asp:ListItem Value="1">Class 1</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnSubmit" runat="server" Text="Show Page" Enabled="False"
PostBackUrl="~/_layouts/MyWebParts/MyAppPage.aspx" />
This works in redirecting the browser to the Application Page I have created, but I am having trouble accessing the form data.
On the Page_Load function of the Application Page I have the following debugging code.
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "";
foreach (String s in Page.Request.Form.AllKeys)
{
Label1.Text += s + ": " + Page.Request.Form[s] + "<br />";
}
}
This shows that the data I need has in fact been posted to the page.
ctl00$m$g_24a73cf8_8190_4ddb_b38b_bf523b12dbd3$ctl00$SemesterSelector: 28
ctl00$m$g_24a73cf8_8190_4ddb_b38b_bf523b12dbd3$ctl00$ClassSelector: 11-0021-A
But when I try to access this as:
Page.Request.Form["ClassSelector"]
Nothing is returned. I know I must be missing something simple here, but I am not sure what.
Any help is greatly appreciated.
Ah, the ASP.NET master page prefix problem! One of my favorites.
The master page for your application page puts a prefix in front of your server-side controls so that they will be unique. If you end up access your control via the Form collection, you have to access it using not only the control ID, but also the ContentPlaceholder prefix. That's why you see such a large ID dumped out of your debugging logic.
If you want to programmatically get to the ID of the control, you can use FindControl, but you'll have to target the apppropriate content placeholder scope for this. Here's a good tutorial/explanation here (which really emphasizes how complex this can get!).
Of course, the other option you can use is just hard-coding the control id based on what you're seeing from your debugging code...but that won't be reliable if you change content placeholders or more your control to a different container.
I guess the answer depends on how static your controls will be.
Hope this helps. Good luck!!
Well to access it that way you would have to use
Page.Request.Form["ctl00$m$g_24a73cf8_8190_4ddb_b38b_bf523b12dbd3$ctl00$ClassSelector"]
As you can actually see from your code where you set the label text to s plus Request.Form[s]
I am usually dealing with c# code , but recently developing a asp.net page , I have a Calendar that Appears and the user selects the date he/she wants. On that page is a asp lbl that i would like to display the currently selected date, which is normally easy for me but i am having trouble referencing/finding the control . Also I am unsure of the best way to do achieve this and i'm sure to come across this problem in the future.
This is where I would like to set the lbl text and have tried using the FindControl method but it's not working for me , thinking its possibly nested as i have some divs?.
public void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
Control Lbl = FindControl("inputField");
if (Lbl != null)
{
//Control mycontrol2 = Lbl.Parent;
Lbl.Text = Calendar1.SelectedDate.ToShortDateString();
}
and this is in asp.
<div id="date">
<input type="text" size="12" id="inputField" />
<script>
$("#inputField").click(function () {
$("#box").show("slow");
});
</script>
</div>
How do I accomplish setting the inputfield text to the Calendar.SelectedDate ?.
(and any tips you have come across yourself if any, for good practice)
Thanks For any help.
Any reason why you're not using an asp:Label? You can't find the "label" because it is an html control, aka a client side control. Use an <asp:Label id="lblCal" runat="server"... and you should have no problem changing its text in code behind:
lblCal.Text = Calendar1.SelectedDate.ToShortDateString();
Asp.Net considers only server tags as being controls available at C# level.
All those DIVs and other tags are just plain text for the Asp.Net, they will no be considered in the control hierachy.
To make Asp.Net consider it in the server, place the runat="server" attribute on the tags of your interest. They will become accessible in the code-behind by the name placed in the id attribute.
Asp.Net will never be abled to find the 'inputField' in your sample code.
Solution:
To solve your problem I recommend you use an Asp.Net WebForm control called TextBox... if what you want is an input:
<asp:TextBox runat="server" id="inputField" />
By doing this, you will be abled to access the inputField, in the code-behind by name:
inputField.Text = Calendar1.SelectedDate.ToShortDateString();
i have the following problem:
i work in web application and only today. any control i put on the page, when trying to access it from behind code. it doesn't appear at all. what are the probabilities and reasons for this problem.
note:
i work from a thin client. they make some maintenance on their server today. and after that i find this problem.
the previous controls on my page can be accessed normally with out any problems.
See if the controls have an ID this might sound stupid but perhaps yesterday someone
created the view with a snippet label *tab *tab and forgot to add an id
Below result of label *tab *tab ..
<asp:Label Text="text" runat="server" />
Should be
<asp:Label Text="text" ID="lblInfo" runat="server" />
Else check the attributes of the page / controls / codebehindfile
make sure the CodeBehindFile attributes are set correctly
see if run at server attribute is properly set on new controls