Solved

Set Variable

Posted on 2009-03-30
9
214 Views
Last Modified: 2013-11-26
I have a link that works so I know I'm getting the correct value.

But what I need to be able to do is in the code behind set the node value to a session value and then do a redirect

What is making this difficult for me is that I want to assign these actions to an ASP Button that is inside a repeater.

So...I THINK I need to do a onClick event and point to code behind?

This works for a simple link.
I need to garb that value in code behind and set to a variable.
<a href='z.aspx?id=<%#GetNodeValue((DirectCast(Container.DataItem, XmlNode))("availabilityInfo"), "inventoryId")%>'>Link</a>
0
Comment
Question by:lrbrister
  • 4
  • 3
  • 2
9 Comments
 
LVL 23

Expert Comment

by:apresto
Comment Utility
Yeh create a LinkButton to point to an event in your code behind. A Link button is a mix between a link and a button. Generally speaking a button allows you to perform and action and a link sends you somewhere. But a link button allows you to perform an action in your code behind using a link instead of a button.
Do you need to assign the value of the session just the once, to a value that corresponds to the button that was clicked? If so you can set the commandargument property of a link button and access i like this in your event:
protected void btn_click(object sender, EventArgs e)
{
     LinkButton lnk = (LinkButton)sender;
     string argument = lnk.CommandArgument;
}
0
 
LVL 7

Accepted Solution

by:
vbwizardry earned 500 total points
Comment Utility
You should be able to do it by assigning the above code tho the CommandArgument property of the button.

<asp:Button ID="Button1" runat="server" Text="Button" CommandName="Whateve" CommandArgument='CommandArgument='<%#GetNodeValue((DirectCast(Container.DataItem, XmlNode))("availabilityInfo"), "inventoryId")%>'

oncommand="Button1_Command" />
 

********************In code behined*************************

protected void Button1_Command(object sender, CommandEventArgs e)

{

    if (e.CommandName == "Whatever")

    {

        Session["node"] = e.CommandArgument;

        Response.Redirect("...");

    }

}

Open in new window

0
 

Author Comment

by:lrbrister
Comment Utility
Hey guys...
Do I just type that button code into the code behind?
This button is inside a repeater and isn't showing up on my dropdown in Visual Studio
0
 
LVL 23

Expert Comment

by:apresto
Comment Utility
As we have stated, you just need to add a property to the button that you already have in your repeated, just add the CommandArgument property to the button, and assign to it the value that you want to access (set as your session) in your code behind.
The othercode is the Click event of the button which you will use to actually retrieve and set to your session variable
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 7

Expert Comment

by:vbwizardry
Comment Utility
Yes simply setup the properties in script view as you would want them to be and add the code behind method to the page to handle the post-back event.
0
 
LVL 23

Expert Comment

by:apresto
Comment Utility
Could you please:
- post your repeater code
- give us the value how you would access it in your ASPX page that you wish to pass to the code behind

then we can demonstrate how it would work
0
 
LVL 7

Expert Comment

by:vbwizardry
Comment Utility
Hi apresto
You don't need to use the Click event. oncommand is simpler in the way that you do not have to cast the sender as a button type and you get all of the info from event args ;)
0
 

Author Comment

by:lrbrister
Comment Utility
Hey guys...
In the attached repeater code look towards the bottom at the <a href=...>
I want that for the btnBookNow
<asp:Repeater ID="Repeater" runat="server">

            <ItemTemplate>

                <table align="center" cellspacing="0" cellpadding="0" border="0" style="width: 540px;

                    border: solid 1px gray;">

                    <tr>

                        <td style="width: 6px;">

                            &nbsp;

                        </td>

                        <td style="width: 528px;">

                            <table align="center" cellspacing="0" cellpadding="0" border="0" style="width: 528px;">

                                <tr>

                                    <td colspan="4" style="height: 30px; vertical-align: bottom;" class="ResortNameText">

                                        Resort:

                                        <%#(DirectCast(Container.DataItem, XmlNode))("resortName").InnerText%>

                                        <span style="color: white">

                                            <%#GetNodeValue((DirectCast(Container.DataItem, XmlNode))("availabilityInfo"), "inventoryId")%></span>

                                    </td>

                                </tr>

                                <tr>

                                    <td align="center" style="vertical-align: top; width: 100px;">

                                        <%-- <img src="images/temp.jpg" />--%>

                                        <img src='http://www.gograndgetaways.com/rci/<%#(DirectCast(Container.DataItem, XmlNode))("resortId").InnerText%>i.jpg'

                                            width="94px" style="border: solid 1px #6e6e6e;" /><br />

                                        <img src='http://www.gograndgetaways.com/rci/<%#(DirectCast(Container.DataItem, XmlNode))("resortId").InnerText%>e.jpg'

                                            width="94px" style="padding-top: 4px; border: solid 1px #6e6e6e;" />

                                    </td>

                                    <td width="10px">

                                        &nbsp;

                                    </td>

                                    <td style="width: 424px; vertical-align: top;">

                                        <table cellpadding="0" cellspacing="0" border="0" style="height: 130px; border: solid 1px gray;">

                                            <tr>

                                                <td colspan="5" height="8px">

                                                </td>

                                            </tr>

                                            <tr>

                                                <td style="height: 70px; width: 6px;">

                                                    &nbsp;

                                                </td>

                                                <td width="116px" class="ResortNameTextWhite" style="background-color: #5e2a36; vertical-align: top;">

                                                    Resort Address

                                                </td>

                                                <td width="2px">

                                                </td>

                                                <td class="ResortNameTextWhite" style="background-color: #5e2a36; width: 294px; vertical-align: top;">

                                                    Address Placeholder

                                                </td>

                                                <td style="background-color: #ffffff; width: 6px !important;">

                                                    &nbsp;

                                                </td>

                                            </tr>

                                            <tr>

                                                <td style="height: 52px;">

                                                    &nbsp;

                                                </td>

                                                <td class="ResortNameTextBlack">

                                                    Resort Info

                                                </td>

                                                <td>

                                                    &nbsp;

                                                </td>

                                                <td class="ResortNameTextBlack">

                                                    Info Placeholder

                                                </td>

                                                <td>

                                                    &nbsp;

                                                </td>

                                            </tr>

                                        </table>

                                    </td>

                                    <td style="width: 6px;">

                                        &nbsp;

                                    </td>

                                </tr>

                            </table>

                            <br />

                            <table align="center" cellspacing="0" cellpadding="0" border="0" style="width: 528px;">

                                <tr>

                                    <td colspan="5" style="height: 30px; vertical-align: bottom;" class="ResortNameTextSmall">

                                        Available Units:<br />

                                        Please select one or more available unit(s) to hold or book:

                                    </td>

                                </tr>

                                <tr>

                                    <td class="dtlheaderBlack">

                                        Unit Type:

                                    </td>

                                    <td class="dtlheaderBlack">

                                        Dates

                                    </td>

                                    <td class="dtlheaderBlack">

                                        Max<br />

                                        Occupancy

                                    </td>

                                    <td class="dtlheaderBlack">

                                        Kitchen Type

                                    </td>

                                    <td class="dtlheaderBlack">

                                        Weekly Prices

                                    </td>

                                </tr>

                                <tr>

                                    <td class="dtlContentBlack">

                                        <asp:RadioButton ID="bookit" runat="server" /><%#GetNodeValue((DirectCast(Container.DataItem, XmlNode))("availabilityInfo"), "inventoryType")%>

                                    </td>

                                    <td class="dtlContentBlack">

                                        <%#GetNodeValue((DirectCast(Container.DataItem, XmlNode))("availabilityInfo"), "checkInDate")%><br />

                                        <%#GetNodeValue((DirectCast(Container.DataItem, XmlNode))("availabilityInfo"), "checkOutDate")%>

                                    </td>

                                    <td class="dtlContentBlack">

                                        <%#(DirectCast(Container.DataItem, XmlNode))("maxOccupancy").InnerText%>

                                    </td>

                                    <td class="dtlContentBlack">

                                        <%#(DirectCast(Container.DataItem, XmlNode))("kitchenType").InnerText%>

                                    </td>

                                    <td class="dtlContentBlack">

                                        $<%#GetNodeValue((DirectCast(Container.DataItem, XmlNode))("availabilityInfo"), "value")%>&nbsp;

                                        <%#GetNodeValue((DirectCast(Container.DataItem, XmlNode))("availabilityInfo"), "currency")%>

                                    </td>

                                </tr>

                                <tr>

                                    <td colspan="5" class="dtlButton">

                                        &nbsp;<asp:Button ID="btnDetails" runat="server" Text="Details"/>

                                        &nbsp;<asp:Button ID="btnHold" runat="server" Text="Hold" />

                                        &nbsp;<asp:Button ID="btnBookNow" runat="server" Text="Book Now"  />

                                        <a href='z.aspx?id=<%#GetNodeValue((DirectCast(Container.DataItem, XmlNode))("availabilityInfo"), "inventoryId")%>'>Link</a>

                                    </td>

                                </tr>

                            </table>

                            <br />

                            <br />

                        </td>

                        <td style="width: 6px;">

                            &nbsp;

                        </td>

                    </tr>

                    <tr>

                        <td align="center">

                        </td>

                    </tr>

                </table>

                <br />

                <br />

            </ItemTemplate>

        </asp:Repeater>

Open in new window

0
 
LVL 23

Expert Comment

by:apresto
Comment Utility
@vbwizardry, thanks, ill remember that one, could come in handy :)
@irbrinster
If you use vbwizardry's suggestion in the second psot of this thread that should solve your problem. You just need to replace your button at the bottom with theone he has provided and add the event to your code behind and it should work fine
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now