Click here to Skip to main content
15,916,527 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,
used Ajax Update Panel then took upload control and show button. data added in the grid but every time refresh the page how can i prevent the refresh?

plz ans me ASAP.U will be highly appreciated.

Code is:

VB
Partial Class ctlFileUpload
    Inherits System.Web.UI.UserControl
    Dim dtFiles As DataTable = Nothing

    Protected Sub btnShow_Click(sender As Object, e As System.EventArgs) Handles btnShow.Click

        If fUpLoad.HasFile Then
            Dim filename As String = Path.GetFileName(fUpLoad.FileName)

            'fUpLoad.SaveAs(Server.MapPath("~/Files/") & filename)
            lblDataUpload.Text = "Upload status: File uploaded!"

            Dim dr As DataRow = dtFiles.NewRow()
            dr.BeginEdit()
            dr(0) = filename
            dr(1) = DateTime.Now.ToString()
            dr.EndEdit()
            dtFiles.Rows.Add(dr)
            ViewState("dtFiles") = dtFiles

            gvShowData.DataSource = dtFiles
            gvShowData.DataBind()

        End If
    End Sub

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            dtFiles = New DataTable()
            dtFiles.Columns.Add("FileName")
            dtFiles.Columns.Add("FileTime")
            ViewState.Add("dtFiles", DirectCast(dtFiles, Object))
            gvShowData.DataSource = dtFiles
            gvShowData.DataBind()
        Else
            dtFiles = DirectCast(ViewState("dtFiles"), DataTable)
        End If
    End Sub

    End Class


XML
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ctlFileUpload.ascx.vb" Inherits="ctlFileUpload" %>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="false"  />
<style type="text/css">
    .style1
    {
        width: 70%;
        border-style: solid;
        border-width: 5px;
    }
    .style2
    {
        height: 32px;
    }
</style>
<asp:UpdatePanel ID="upDatePanel" runat="server" UpdateMode="Conditional">

    <ContentTemplate>
        <table align="center" cellpadding="3" cellspacing="4" class="style1">
            <tr>
                <td class="style2">
                    <asp:FileUpload ID="fUpLoad" runat="server" />
                </td>
                <td class="style2">
                    </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="btnShow" runat="server" Text="Show" />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblDataUpload" runat="server"></asp:Label>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td rowspan="3">
                    <asp:GridView ID="gvShowData" runat="server">
                    </asp:GridView>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
    </ContentTemplate>
 </asp:UpdatePanel>
Posted
Updated 3-May-12 11:02am
v2

1 solution

EnablePartialRendering="false" 

The first thing I see - you have disabled partial page update :)
 
Share this answer
 
Comments
Sandeep Mewara 4-May-12 2:18am    
Bingo! 5!
khosnur 4-May-12 9:17am    
without false doucument file name is not coming in the grid

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900