ASP.NET webform Fileupload inside an ascx which is inside an updatepanel in the aspx - asp.net

here is some code in my page :
<asp:UpdatePanel ID="UpdatePanelEQSelector" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc12:EQSelector ID="custEQSelector" OnEqChange="custEQSelector_OnEqChange" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
Inside my user Control, I'm asked to add a fileuploader.
After coding it simply, I tested and my fileuploader is always empty.
I've searched a while and discovered that it was a normal behavior.
The solution to make it work is to add a PostBackTrigger for the updatePanel.
When I tested it in my aspx page, I achieved to do it and my fileUploader had the file.
Then I tried to add it dynamically (to finally do it in my control), it worked with that :
PostBackTrigger trigger = new PostBackTrigger();
trigger.ControlID = this.btnTest.ID;
this._UpdatePanelEQSelector.Triggers.Add(trigger);
But I can't manage to make this code work in my control (I passed my updatePanel as a parameter to my control set in Load, the fileUpload is always empty)
Do you see a solution ?
Thanks

Does it postback, but leaves the control empty? or is it not posting back at all. If it's not posting back at all I'd add this
ScriptManager.GetCurrent(this).RegisterPostBackControl(btnTest);
to the page_load of the user control.
If it is posting back, but the control is empty, then I'd wager there is probably some dodgy html somewhere on the page and the values are getting lost.

Related

User control retains focus incorrectly after TextChanged postback when UC is contained within a detailsview control

I reference a previous post: Focus lost on partial postback with UserControls inside UpdatePanel
where an excellent solution works perfectly for web-page controls within a form.
However, I have placed my UC inside a detailsview template-field (for Edit+Insert).
The UC contains an UpdatePanel needed to adjust the text-formatting and control's style(s) following the TextChanged event of the UC-textbox (AutoPostback=True) during the Edit-mode and Insert-modes of the DetailsView.
As such, when the DetailsView-control is in Edit-mode, and user changes Text in the UC, the textchanged event is fired and the user-entered value is validated and when OK, the thousounds-separator (comma) are added to the UC-textbox-text, BUT, the focus moves to the next field in the DetailsView and QUICKLY returns back to the UC-control.
This incorrect focus-move(s) does NOT occur when the UC is wrapped in updatepanels as noted in the referenced post since the focus and tabbing order works perfectly outside of the DetailsView control.
Here is the aspx markup for the template-field-EDIT (only).
<asp:TemplateField HeaderText="Initial Mileage" SortExpression="IMilage">
<EditItemTemplate>
<asp:UpdatePanel ID="updpnlIMilage" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<TGANumeric:GANumeric ID="ucnumIMileage" runat="server"
Caption="Initial Mileage" HideCaption="True" Width="160"
DisplayMask="999,999" InputMask="999999"
Enabled="True" IsRequired="False"
MinNumber="0" MaxNumber="999999"
Text='<%# Bind("IMilage") %>'
TabIndex="0"
/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ucnumIMileage" />
</Triggers>
</asp:UpdatePanel>
</EditItemTemplate>
Thanks in advance. Your comments are welcome.
Thanks...J.
So are you saying your control hierearchy (partial) is:
UpdatePanel > TGANumeric:GANumeric > UpdatePanel > TextBox
This is an awful lot of overhead to just format a number with a comma, which is the only reason I see for your posting back. As far as I can tell there is nothing you need from the server, so why post?
Or is there?
My thoughts, lose the update panels, disable the AutoPostback on the Textbox, handle the formatting client side if it must be seen immediately, or leave the formatting to the DetailsView field DataStringFormat when it posts after save.
I'm betting this will clear up any focus issues.
Based on all the comments in this thread, I want to explain the actual root cause of the tabbing misbehavior.
1) There were no coding issues or event-issues with the user-control.
2) There were no coding issues or event-issues with the layering of Master-page, Content-page, Ajax update-panels / nested update-panels, details-view and template-fields containing the user-control.
3) The real culprit was a small snippet of code where the page adjusts the web-controls on the form based on the "state" (status) of the page/form. I manage the adjusting of visible and/or enabling of web-controls in a single subroutine in the code-behind so that all of this enabling/disabling visible/not-visible occurs in one place under a set of CASE-statements.
The actual erroneous snippet of code inside the 'sbSetFormState()'-method was messing with the class-variable 'm_eFormState' that actually caused the update panel to re-fire and thus the tabbing got thrown out of sequence.
This was discovered by the great suggestion from 'fnostro' to remove or add functionality features until the mis-behavior exposes itself.
I mark this topic as resolved/closed.
Again, thanks to fnostro !!!

how to clear gridview without reloading the page

I have a gridview control on my asp.net page(vb.net). I also have a "cancel" button, that when pressed, is supposed to clear the gridview of it's current contents.
However whenever the cancel button is pressed, it just reloads the page and the gridview is still there with the same data that I wanted clear.
Based on suggestions that I found on stackoverflow, I set the datasource to nothing, but that is not working.
Here is my code for the cancel button:
Private Sub btnCancel_Click(sender As Object, e As System.EventArgs) Handles btnCancel.Click
gvQuizReport.DataSource = Nothing
gvQuizReport.DataBind()
End Sub
Any suggestions would be welcome!
Thanks
You might try:
gvQuizReport.Columns.Clear()
though as #Leniel Macaferi said, hiding the gridview is a possible solution as well.
since you have shown some interest in updatepanels, here is some starter code in case you are unfamiliar:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
If you already have a scriptmanager on your page you don't need to add another (you will get an error). if you have any problems implementing the updatepanel, feel free to post another question, there are plenty of people to help you with it
The code you showed should "clear" the results, but if you do not want anything displayed, you would hide the gridview by using gvQuizReport.Visible = False;
If you really want to clear without reloading the page, you could just use client side script to hide the grid object.
jquery hide

How can I refresh a dropdownlist during an event of another dropdownlist without refreshing whole web page?

I am developing my first asp.net website, my requirement is to refresh DropDownListB at SelectedIndexChanged event of DropDownListA, I have set AutoPostBack="True" for DropDownListA. Now the problem is whole web page gets refreshed, its unnecessary for me, is there any other technique that i can use to refresh only that control or only that panel rather than refreshing whole page?
Put the dropdowns inside
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
// Dropdowns
</ContentTemplate>
</asp:UpdatePanel>
and include <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager> at the top
1- You can simply place the dropdown in an UpdatePanel, this will avoid a complete post back.
You can get more details on UpdatePanel here
2- You can use jQuery AJAX to fetch the data in JSON format and bind it to the dropdown list, this approach is more efficient but little complex in comparison to UpdatePanel
You can find so many articles on this if you search this on google , like
[EDIT]
You can find a similar implementation here

gridview delete command within updatepanel, and separate __doPostback() functionality

I have a gridview within an updatepanel, the rows have a delete button which removes that row.
Elsewhere, I run code to insert a row. Following this insert I run __doPostback() with the ID of the updatepanel, then in the updatepanel's load() event I call databind() on the gridview.
As soon as I implement the __doPostback() and databind, the inbuilt gridview delete stops working! :( The actual refresh/databind when adding the row works well.
How can I overcome this? I guess something may be awry in that when clicking on the delete button, the databind is conflicting with the inbuild delete/refresh functionality?
Thanks!
EDIT: Apologies if the question isn't described well...
Essentially, I wish to have a gridview with built-in delete functionality through the datasource and command column etc. inside of an updatepanel. I also want to update this panel seperately, but when I put in this separate update code (gridview.databind in the updatepanel.load) it breaks the standard delete functionality. Hope that is clear :)
You've tried put the UpdatePanelMode as Conditional and use UpdatePanel.Update() besides the ClientScript.RegisterStartupScript during your insertion block ?
I believe the problem is that the event is inside of the GridView and you can't access them as easily as you can with something like a Button. To register the GridView to make the Async events you need to attach it to the ScriptManager.
To do this you use the RegisterAsyncpostBackControl method.
Here is a general idea of how to do it.
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server">
<%-- your fields, etc --%>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
In your code behind you do
protected void Page_Load()
{
ScriptManager1.RegisterAsyncPostBackControl(GridView1);
}
It's been a while since I've done this but I believe this will allow the GridView to function as you'd expect, except you don't need the extra DataBind() I don't believe in this case.
You can also set the UpdatePanel to Conditional and fire an UpdatePanel1.Update() on top of this as Jeison suggested.
You can find some added details at http://msdn.microsoft.com/en-us/library/bb386452.aspx
If you still have trouble, let us know what happened.
It seems like you calling DataBind() of GridView every time the UpdatePanel load after the insert button click, it reload the data before delete reaches the DataSource.
EDIT
If so, you can add boolean eventArgument in __doPostBack(updatePanelId, "true"). And using this you could add a condition in your updatepanel load event like
if(this.updatepanel1.Page.Request.Params["__EVENTARGUMENT"] == "true"]
this.gridview.databind()
Hope this will resolve the issue.

ASP.NET Fileupload and AJAX

I have a little problem with the FileUpload and uploadpanels.
As most of you probably knows you cannot use the asp:FileUpload control without forcing a postback. At least not what I know of, let me know if I am wrong.
Now my problem is:
I have a usercontrol with a FileUpload and a button that says "Upload". This UserControl is loaded into a UpdatePanel.
Now I want to register to the upload button inside the usercontrol as a postback trigger.
Is there any way to do this?
Does anyone know of a way to make fileuploads without postbacks?
Best Regards
The real napster
Solved this issue
If anyone meets this challenge it can be solved by doing this in your UserControl
ScriptManager sman = ScriptManager.GetCurrent(Page);
sman.RegisterPostBackControl(btn_addDocument);
You need to add a trigger to your UpdatePanel control to force the button that submits the page to perform a full postback. An example would be:
<triggers>
<asp:postbacktrigger controlid="btnSave" />
</triggers>

Resources