Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Set Variable

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
lrbrister
Asked:
lrbrister
  • 4
  • 3
  • 2
1 Solution
 
aprestoCommented:
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
 
vbwizardryCommented:
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
 
lrbristerAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
aprestoCommented:
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
 
vbwizardryCommented:
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
 
aprestoCommented:
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
 
vbwizardryCommented:
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
 
lrbristerAuthor Commented:
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
 
aprestoCommented:
@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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now