Category Archives: DataList

[RESOLVED] How to prevent browser from caching image, Trsponse.Cache.NoStore didn't work

I have a datalist in which I am storing one image. when the user uploads a new image,

I rebind the datalist as shown in codebehind. However the browser seems to be caching the image. I have to manually

refresh the page to get the new image to appear. How do I get the new image to appear right away.

Thanks for assistance

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Response.Cache.SetNoStore() Dim cf As New CommonFunctions Dim locationkey(3) As Integer Dim PersonIsREProfessional As Boolean Dim dt As New DataTable Dim IncludesAddress As Boolean = True If Not IsPostBack Then AutoCompleteExtenderProf.ContextKey = "" AutoCompleteExtenderNonProf.ContextKey = "" PopulateDdlCountry() If CInt(Session("SelectedPersonID")) <> 0 Then '***** Set Panel Visibility Profession = cf.GetPersonProfession(Session("SelectedPersonID")) If Profession <> String.Empty Then PersonIsREProfessional = True Else PersonIsREProfessional = False End If dt = cf.GetPersonData(Session("SelectedPersonID")) If dt.Rows.Count = 0 Then 'No data If PersonIsREProfessional = True Then dt = cf.GetPersonProfessionalData(Session("SelectedPersonID"), Profession) If dt.Rows.Count = 0 Then dt = cf.GetPersonProfessionalData_WO_Address(Session("SelectedPersonID"), Profession) End If Else dt = cf.GetPersonData_WO_Address(Session("SelectedPersonID")) IncludesAddress = False End If End If PopulateDataList(dt) ' This is just the NonProfile image End If End If End Sub Protected Sub UpdateButtonNonProf_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim cf As New CommonFunctions Dim dt As New DataTable FName:=txtEditNonProfFirstName.Text, LName:=txtEditNonProfLastName.Text, _ PhoneMobile:=txtEditNonProfPhoneMobile.Text, PhoneHome:=txtEditNonProfPhoneHome.Text, PhoneOffice:=txtEditNonProfPhoneOffice.Text, _ Extension:=txtEditNonProfExtension.Text, _ EMail:=txtEditNonProfEMail.Text, Fax:=txtEditNonProfFax.Text, StreetAddr1:=txtEditNonProfStreetAddress1.Text, StreetAddr2:= _ txtEditNonProfStreetAddress2.Text, City:=lblEditNonProfCity.Text, State:=lblEditNonProfState.Text, PostalCode:=txtEditNonProfPostalCode.Text, _ Country:=ddlEditNonProfCountry.SelectedValue, IsREProfessional:=False, Profession:="", _ InhibitEMailAlerts:=chkEditNonProfInhibitEmailAlerts.Checked) PanelVisibility(ItemNonProfPanelVisible:=True, EditNonProfPanelVisible:=False, _ ItemProfPanelVisible:=False, EditProfPanelVisible:=False) '**** Insert Image Data And imgid which=person id If FileUploadEditNonProf.PostedFile IsNot Nothing And _ FileUploadEditNonProf.PostedFile.FileName <> "" Then Dim fileName As String = FileUploadEditNonProf.PostedFile.FileName Dim ext As String = fileName.Substring(fileName.LastIndexOf(".")) ext = ext.ToLower Dim imgType = FileUploadEditNonProf.PostedFile.ContentType If cf.ExtensionOK(ext) Then Dim image_file As System.Drawing.Image = System.Drawing.Image.FromStream(FileUploadEditNonProf.PostedFile.InputStream) arrContent1 = cf.ResizeImageWL(64, 70, image_file) intLength1 = arrContent1.Length arrContent2 = cf.ResizeImageWL(23, 24, image_file) intLength2 = arrContent2.Length If cf.Doc2SQLServer2Inputs(Session("PersonID"), arrContent1, intLength1, _ arrContent2, intLength2, imgType) = True Then '****If no image, no problem,- avatar will be accessed End If End If End If PopulateDataList(dt) End Sub Protected Sub PopulateDataList(ByVal dt As DataTable) Dim cf As New CommonFunctions Dim dtlPersonImages As DataList = cf.FindControlRecursive(Master.Page, "dtlPersonImages") 'Dim ImgID As Integer '**** Begin bind to datalist **** dt.Columns.Add("PseudoPersonId") For i = 0 To dt.Rows.Count - 1 '**** Get image ***** If IsDBNull(dt.Rows(i).Item("ImgExt")) Then 'no image was uploaded 'Stuff in 0 so that avatar will be used dt.Rows(i).Item("PseudoPersonId") = 0 dt.Rows(i)("imgext") = "png" Else 'use actual personid dt.Rows(i).Item("PseudoPersonId") = dt.Rows(i).Item("PersonId") End If Next dtlPersonImages.DataSource = dt dtlPersonImages.DataBind() '**** End bind to datalist **** End Sub

You could append a querystring value to the end of the image url, the browser would then think its a new image and grab it again.  You could use some time value (seconds):

image.jpg?t=123465

Thank you. Very clever.

[RESOLVED] ImageButton control

hello to all

               i would like to ask some help coz i dont know how am i going to get the value when the user click my imagebutton, here the scenario

i have an imagebutton on my datalist with an image of checbox, now when the user what to click the imagecheckbox the image will change to check image then when the user what to uncheck the item the imagebutton will change to uncheckimage , now how am i going to do that using click event of the control..sample codes is highly appreciated.

if you'll ask me why i dont what to use the checkbox control it because i dont know how to adjust the control to a to its heights and width.. that is why i try to use the imagebutton in case there is a way to do it.

thanks

Hi

Here you can see how to grab the ImageButton event which is inside a Datalist:
http://msdn.microsoft.com/en-us/library/df6hth3s%28v=VS.90%29.aspx

In order to differentiate between checked/unchecked of the ImageButton, you can alter the example method like that:

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
	ImageButton imb = e.Item.FindControl(<the ImageButton ID in the Datalist ItemTemplate>);
	if (imb != null) {
		if (imb.CommandArgument == "checked")
		{
			imb.CommandArgument = "unchecked";
			imb.ImageUrl = "Unchecked.png";
			// Do 'unchecked' related operations..
		}
		else
		{
			imb.CommandArgument = "checked";
			imb.ImageUrl = "checked.png";
			// Do 'checked' related operations...
		}
	}
}

By the way, what's the deal with changing the height or width of a Checkbox...?

Amit

This can also be done using jQuery just see the below code :-

 

<script type="text/javascript">
        $(function () {
            $('input[type="image"]').toggle(
            function () {
                $(this).attr("src", "IMAGES/yes_bw.gif");
                return false;
            },
            function () {
                $(this).attr("src", "IMAGES/yes_green.gif");
                return false;
            }
            );
        });
    </script>

Think this would be helpfull...

it is because my users is in old age people they cant see that little checkbox, that's i'm trying to raise in this forum if there are solutions for that control..anyway i will try to use your code..thanks a lot i'll mark this answer later..

hi ambran

              how can i set to false for autopostback on my imagebutton? anyway i got it to work with the given code you have but the problem is the postback on the imagebutton..

 

thanks

jQuery will be more helpfull with clientside work from my example just see....above

As an ImageButton is a button, you can't prevent it from posting back to the server. The same applies for other buttons as LinkButton and normal button. This postback is neccesary in order to run the code I posted.

If you want to avoid posting back to the server, you'll need to use a normal html button, and apply Javascript to this html button's onclick (client) event for the actions as Smruti suggested in the previous post.

Amit

[RESOLVED] A Table that is repeated throughout my site: Is this possible

Hi I want to repeat this code throughout my website:

<asp:Table Width="95%" runat="server" HorizontalAlign="Center" CellPadding="10">
            <asp:TableRow>
                <asp:TableCell HorizontalAlign="Center">
                    Copyright Me
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>

 

And then I was trying to put this in a c# file:

 

public const string m_Copyright =
            "<asp:Table Width=\"95%\" runat=\"server\" HorizontalAlign=\"Center\" CellPadding=\"10\">" +
                "<asp:TableRow>" +
                    "<asp:TableCell HorizontalAlign=\"Center\">" +
                        "Copyright Me" +
                    "</asp:TableCell>" +
                "</asp:TableRow>" +
            "</asp:Table>";

 

And then insert this into a aspx page with

 

<%=MyWebsite.GeneralCode.MyConsts.m_Copyright%>

 

But needless to say it does not work. It just shows the 'Copyright me' bit with none of the table alignment.

Is this possible what I am trying or do I have to put the table on each page?

 

Hi,

either place your code on a master page and make use of the master page for every content web form (recommended practice anyway).

Another way is to put the code on a user control and place the user control on those pages where you need it.

Also, I don't know why you're making it a <asp:Table> in the first place. It'll eat resources for nothing. Best is to replace it with a simple <table> element in pure html and use CSS to style it.

Grz, Kris.

Thanks.

Just as a point of interest, when should I use a asp:Table rather than table?

 

jaa17

when should I use a asp:Table rather than table?

Honestly, I don't really remember when I used it myself since 2002 besides demo purposes or so. If you have something like your situation simply go for the <table> html element. If you need to show tabular data coming from some data source (database, xml, rss feed, alien spaceship, ...) simply make use of the data presentation controls like repeater, datalist, listview, gridview, ...

Grz, Kris.

[RESOLVED] How do i maintain state of clicked menuitem in menu control

I have menu control like as following:

<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" StaticEnableDefaultPopOutImage="False"
                                                OnMenuItemClick="Menu1_MenuItemClick"  Font-Bold="True" Font-Names="Tahoma" BackColor="Silver">
                                                <Items>
                                                    <asp:MenuItem ImageUrl="Images/selectedtab2011.GIF" Text="" Value="0"></asp:MenuItem>
                                                    <asp:MenuItem ImageUrl="Images/unselectedtab2010.GIF" Text="" Value="1"></asp:MenuItem>
                                                    <asp:MenuItem ImageUrl="Images/unselectedtab2009.GIF" Text="" Value="2"></asp:MenuItem>
                                                    <asp:MenuItem ImageUrl="Images/SRunselectedtab.GIF" Text="" Value="3"></asp:MenuItem>
                                                </Items>
 </asp:Menu>


It gives o/p as tabs: 2011 2010 2009 2008


When i click on each tab i am displaying tab corresponding items with MultiView Control as follows:


<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
                                                <asp:View ID="Tab1" runat="server">
                                                <div style="height: 310px; width: 780px; overflow:auto ">
                                                        <asp:DataList ID="dList2011" runat="server" RepeatDirection="Horizontal"
                                                            RepeatColumns="5" onitemdatabound="dList2011_ItemDataBound">
                                                            <ItemTemplate>
                                                                <asp:HyperLink ID="hlnk3" runat="server" ToolTip='<%# Bind("VideoName") %>' NavigateUrl='<%# Eval("ID", "Archives.aspx?ID={0}") %>'>
                                                                    <asp:Image ID="img3" runat="server" Width="150px" Height="100px" ImageUrl='<%# Bind("Thumbnail") %>' />
                                                                </asp:HyperLink>
                                                            </ItemTemplate>
                                                        </asp:DataList>
                                                    </div>
                                                </asp:View>

</asp:MultiView>


Suppose if i click on 2010 tab, it is showing corresponding datalist items well. If i select one of datalist items under this tab, again it is showing "First Tab (2011)"  instead of showing 2010 as highlighted.


How do i maintain the tab state in page round trips after selecting the items under that tab?

ravikirantummala2000

If i select one of datalist items under this tab, again it is showing "First Tab (2011)"  instead of showing 2010 as highlighted.

Are you trying to highlight the selected Menu Item? If so, you have to set MenuItemStyles like this example

<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" StaticEnableDefaultPopOutImage="False"
    OnMenuItemClick="Menu1_MenuItemClick" Font-Bold="True" Font-Names="Verdana" BackColor="#FFFBD6"
    DynamicHorizontalOffset="2" Font-Size="0.8em" ForeColor="#990000" StaticSubMenuIndent="10px">
    <DynamicHoverStyle BackColor="#990000" ForeColor="White" />
    <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
    <DynamicMenuStyle BackColor="#FFFBD6" />
    <DynamicSelectedStyle BackColor="#FFCC66" />
    <StaticHoverStyle BackColor="#990000" ForeColor="White" />
    <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
    <StaticSelectedStyle BackColor="#FFCC66" />

    <Items>
        <asp:MenuItem ImageUrl="Images/selectedtab2011.GIF" Text="" Value="0"></asp:MenuItem>
        <asp:MenuItem ImageUrl="Images/unselectedtab2010.GIF" Text="" Value="1"></asp:MenuItem>
        <asp:MenuItem ImageUrl="Images/unselectedtab2009.GIF" Text="" Value="2"></asp:MenuItem>
        <asp:MenuItem ImageUrl="Images/SRunselectedtab.GIF" Text="" Value="3"></asp:MenuItem>
    </Items>
</asp:Menu>

Menu Items displaying as follows:

2011    2010   2009  2008

When i click on 2010 Menu item. The Items displaying under 2010 with Multiview as follows :

Item1      Item 2   Item3   Item4

Now i cick on "Item 1" the page is showing 2011 menu item as highlighted instead of showing Item list under tab 2010

I need to maintain the tab state as it is even though i selected items under that particular tab

How do i resolve this?

Hi,

ravikirantummala2000

Now i cick on "Item 1" the page is showing 2011 menu item as highlighted instead of showing Item list under tab 2010

I need to maintain the tab state as it is even though i selected items under that particular tab

How do i resolve this?

I would like to suggest you to check the links below for the similar threads which provide some solutions for the same issue.

if the menuitem included a navigateUrl , selected property does not work.

how to highlight the selected asp menu item?

Hope this helps.

[RESOLVED] Wizard control space issue

Hi there,

I have a question. I have a wizard control on top of a datalist. By default I set visible to false. then the problem appears, the wizard control takes five lines to sixe lines of spaces. How can I eliminate the space when Wizard control is invisible?

Thanks

Ben

 

 

 

 

 

Try keeping the Wizard Control in a panel and hide the panel instead. Make sure you don't have extra line breaks("<br/>") in your markup as well.

I found your claim surprising, so I tested it.  As I suspected, when you set visible to false, the control in question is not rendered to the client.  So I don't see how the wizrad control would take up any space at all.  I confirmed this with a quick test.

You must have something else going on.

You are right. It is the </br> in the markup within <div> outside the wizard control that takes up the spaces. So my issue is not the wizard control. Wizard control wont take up spaces when it is invisible, Thank you guys for all your suggestions.