locked
get value/session value without post back RRS feed

  • Question

  • User1413654275 posted

    hi there, 

    i have a datalist that show colors (.png files), when i choose color from the datalist i have a picture that change base on the color selection , this part i got with no problem now how can make it change without page postback/refresh also when i click the color from the datalist there is value saved in session i also want to keep that 

    PLEASE HELP !!!!

    Monday, June 2, 2014 2:20 AM

All replies

  • User2103319870 posted

    lga1981

    how can make it change without page postback/refresh

    Try adding an UpdatePanel to your Datalist control like given below

     <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
            <ContentTemplate>
                <%--Your DataList control--%>
            </ContentTemplate>
        </asp:UpdatePanel>

    Monday, June 2, 2014 2:27 AM
  • User1413654275 posted

    it's not doing the post back but also not changing the image link when i choose color from the datalist

    Monday, June 2, 2014 2:36 AM
  • User1243880387 posted

    UpdatePanel must work, but it can create some problem in updating the session. (As it did in my case).

    Please post your code, after looking at the same we can find a way around.

    Monday, June 2, 2014 2:42 AM
  • User1413654275 posted

    this is the aspx:

    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" >
    <ContentTemplate>
    <asp:DataList ID="cushion_fabric" runat="server" DataSourceID="fabric_selection" RepeatColumns="5" Width="555px" OnSelectedIndexChanged="DataList1_SelectedIndexChanged" DataKeyField="fabric_name">
    <ItemTemplate>
    <asp:ImageButton ID="ImageButton1" runat="server" AlternateText='<%# Eval("fabric_name") %>' Height="120px" ImageUrl='<%# "http://www.oresther.net/fabric/160x120/" +Eval("fabric_name", "{0}") + ".jpg" %>' CommandName="Select" />
    </ItemTemplate>
    </asp:DataList>
    </ContentTemplate>
    </asp:UpdatePanel>
    </div>

    this is the .cs file

    protected void DataList1_SelectedIndexChanged(object sender, System.EventArgs e)
    {

    string selected_shape = (string)(Session["selected_shape_s"]);
    string selected_cushion_fabric = cushion_fabric.SelectedValue.ToString();

    Image1.ImageUrl = "http://www.oresther.net/models/CHAIR/CHAIR_CR/Left/Ties/" + selected_cushion_fabric + ".png";
    }

    without the update panel it's working but with post back

    Thank You For Your Help

    Monday, June 2, 2014 2:48 AM
  • User1243880387 posted

    Have you tried debugging that as soon as you click on the color, the control goes to the code?

    Check if the image is getting the url properly?

    You can also try setting the image url in javascript, if you are able to add data in session and only image url is not getting set.

    Monday, June 2, 2014 3:02 AM