Solved

Set Variable

Posted on 2009-03-30
9
219 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
ID: 24019227
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
ID: 24019248
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
ID: 24019296
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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 23

Expert Comment

by:apresto
ID: 24019346
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
 
LVL 7

Expert Comment

by:vbwizardry
ID: 24019356
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
ID: 24019361
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
ID: 24019390
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
ID: 24019975
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
ID: 24020072
@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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

828 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