?
Solved

How do I get a piece of data into a URL querystring using an <asp:LinkButton> ?

Posted on 2009-04-21
20
Medium Priority
?
285 Views
Last Modified: 2012-05-06
I'm almost there!

I have a javascript confirm on a delete operation.  I believe if I can simply create the necessary URL querystring it will work.  The querystring is working fine for the other operations I'm doing.  I haven't been able to get the JobID into the querystring while at the same time implementing the confirm.  Deleting without a confirm is no problem, but the client wouldn't like that.

The querystring needs to be
EmployerJobsEdit.aspx?JobID=0&Action=Delete
where the zero in "JobID=0" actually has a JobID

I used the code from the hyperlink field in the gridview that does work and put it into the LinkButton, but it doesn't pick up the JobID.
<%@ Page Title="EDCC Career Action Center - Edit Jobs" Language="VB" MasterPageFile="~/Employer.master" AutoEventWireup="false" CodeFile="EmployerJobsEdit.aspx.vb" Inherits="JobsEdit" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link href="CAC.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="information" Runat="Server">
 
 
<br />
 
<table width="660px" border="0" cellpadding="0" cellspacing="0">
<tr>
    <td width="510px" class="EmployerSmallTitle" valign="bottom">Current Job Postings:</td>
    <td width="150px">
        <img src ="graphics/edit.gif" alt="Edit Job" />&nbsp; = Edit Job <br />
        <img src ="graphics/activate.gif" alt="Activate Job" />&nbsp; = Activate Job <br />
        <img src ="graphics/deactivate.gif" alt="Deactivate Job" />&nbsp; = Deactivate Job <br />
        <img src ="graphics/delete.gif" alt="Delete Job" />&nbsp; = Delete Job 
    </td>
</tr>
</table>    
 
<br /><br />
 
    <asp:SqlDataSource ID="JobSummary" runat="server" 
        ConnectionString="<%$ ConnectionStrings:EditJobsConnectionString %>" 
        SelectCommand="SELECT * FROM [Jobs] WHERE ([EmpID] = @EmpID) ORDER BY [Status], [JobTitle], [DateJobAdded]" 
        DeleteCommand="DELETE FROM [Jobs] WHERE [JobID] = @JobID" 
        UpdateCommand="UPDATE [Jobs] SET [Status] = @Status WHERE [JobID] = @JobID">
        <SelectParameters>
            <asp:SessionParameter Name="EmpID" SessionField="EmpID" Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="JobID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="Status" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>
 
<table width="660px" border="0" cellpadding="0" cellspacing="0">
<tr>
    <td align="center">
 
    <asp:GridView ID="GridViewJobListing" runat="server" AutoGenerateColumns="False" 
        BackColor="#000099" BorderStyle="Double" DataSourceID="JobSummary" 
        ForeColor="#FF9933" GridLines="None" HorizontalAlign="Center" 
        Width="600px" DataKeyNames="JobID" BorderColor="#999966" BorderWidth="6px" 
        AllowPaging="True" AllowSorting="True" PagerSettings-PageButtonCount="20" 
            HeaderStyle-Wrap="False" HeaderStyle-HorizontalAlign="Center" PageSize="20">
    <PagerSettings PageButtonCount="20"></PagerSettings>
 
        <RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
        <Columns>
            <asp:BoundField DataField="JobTitle" HeaderText="Job Title" SortExpression="JobTitle" />
            <asp:BoundField DataField="JobStartDate" HeaderText="Start Date" SortExpression="JobStartDate" />
            <asp:BoundField DataField="DateJobAdded" HeaderText="Date Added" SortExpression="DateJobAdded" DataFormatString = "{0:d}" />
            <asp:BoundField DataField="DateLastModified" HeaderText="Modified" SortExpression="DateLastModified" DataFormatString = "{0:d}" />
            <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
            <asp:HyperLinkField DataNavigateUrlFormatString="~/EmployerEditJobWizard.aspx?JobID={0}" DataNavigateUrlFields="JobID" Text="<img src='graphics/edit.gif' alt='Edit Job' title='Edit Job' border='2' />" /> 
            <asp:HyperLinkField DataNavigateUrlFormatString="~/EmployerJobsEdit.aspx?JobID={0}&Action=Activate" DataNavigateUrlFields="JobID" Text="<img src='graphics/activate.gif' alt='Activate' title='Activate' border='2' />" /> 
            <asp:HyperLinkField DataNavigateUrlFormatString="~/EmployerJobsEdit.aspx?JobID={0}&Action=Deactivate" DataNavigateUrlFields="JobID" Text="<img src='graphics/deactivate.gif' alt='Deactivate' title='Deactivate' border='2' />" /> 
            <asp:HyperLinkField DataNavigateUrlFormatString="~/EmployerJobsEdit.aspx?JobID={0}&Action=Delete" DataNavigateUrlFields="JobID" Text="<img src='graphics/delete.gif' alt='Delete Job' title='Delete Job' border='2' />" /> 
            <asp:BoundField DataField="Expr1" HeaderText="Expr1" SortExpression="Expr1"  Visible="False" />
            <asp:BoundField DataField="JobID" HeaderText="JobID" InsertVisible="False" ReadOnly="True" SortExpression="JobID"  Visible="False" />
            <asp:BoundField DataField="EmpID" HeaderText="EmpID" SortExpression="EmpID"  Visible="False" />
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton ID="linkDelete" runat="server" Text="Delete" ForeColor="Silver" PostBackUrl="~/EmployerJobsEdit.aspx?JobID={0}&Action=Delete" OnClientClick="return confirm('Are you sure you want to delete this job?');"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>                            
        </Columns>
        <SelectedRowStyle BackColor="#FFCC66" ForeColor="#000066" />
        <HeaderStyle BackColor="#999966" ForeColor="#000099" HorizontalAlign="Center" 
            BorderColor="#CC6600" BorderStyle="Solid" BorderWidth="5px" />
        <AlternatingRowStyle BackColor="#003399" />
    </asp:GridView>
    </td>
</tr>
</table>
 
</asp:Content>

Open in new window

screenshot.gif
0
Comment
Question by:spaceneedlejumper
  • 11
  • 9
20 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24202998
The reason is this attribute of the HyperLink Field
DataNavigateUrlFields="JobID".

To compensate, try using following in the LinkButton

PostBackUrl="~/EmployerJobsEdit.aspx?JobID='<%#Eval("JobID")#'&Action=Delete"
0
 

Author Comment

by:spaceneedlejumper
ID: 24203599
CodeCruiser:

I tried your code just the way you had it in the LinkButton and got "The server tag is not well formed."

I got the same error when I changed it to
PostBackUrl="~/EmployerJobsEdit.aspx?JobID='<%#Eval("JobID")#%>'&Action=Delete"
and this
PostBackUrl="~/EmployerJobsEdit.aspx?JobID='<%#Eval("JobID")%>'&Action=Delete"
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 24203767
I tested it on my pc and the following works
PostBackUrl="~/EmployerJobsEdit.aspx?JobID='<%#Eval("JobID")%>'&Action=Delete"

Or you can try

PostBackUrl="~/EmployerJobsEdit.aspx?JobID=" & "'<%#Eval("JobID")%>'" & "&Action=Delete"
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:spaceneedlejumper
ID: 24203825
I tried both of those an neither of them work on the production server.

Are you putting that code into the LinkButton or the HyperlinkField?

I keep getting "Server tag is not well formed"
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24203843
I put them in LinkButton. That's where you need it isn't it?
0
 

Author Comment

by:spaceneedlejumper
ID: 24203865
Yes.  I don't know why it doesn't work if it's working on your machine.  Any ideas?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24204014
Try removing the single quotes as follows
PostBackUrl="~/EmployerJobsEdit.aspx?JobID=<%#Eval("JobID")%>&Action=Delete"


http://www.west-wind.com/Weblog/posts/5364.aspx
0
 

Author Comment

by:spaceneedlejumper
ID: 24204106
OK, at least I got it to run.  I had to change your code as follows:

PostBackUrl="~/EmployerJobsEdit.aspx?JobID=<%#Eval('JobID')%>&Action=Delete"

The only problem is now in the querystring
http://bucket.sandbox.edcc.edu/CAC/EmployerJobsEdit.aspx?JobID=%3C%#Eval(%27JobID%27)%%3E&Action=Delete

It should be
http://bucket.sandbox.edcc.edu/CAC/EmployerJobsEdit.aspx?JobID=15&Action=Delete

what can I do about that?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24204116
Now try this syntax
PostBackUrl="~/EmployerJobsEdit.aspx?JobID=" & <%#Eval('JobID')%> & "&Action=Delete"
0
 

Author Comment

by:spaceneedlejumper
ID: 24204131
Server tag is not well formed.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24204162
PostBackUrl="~/EmployerJobsEdit.aspx?JobID=" & <%#Eval("JobID")%> & "&Action=Delete"
0
 

Author Comment

by:spaceneedlejumper
ID: 24204182
Again.   The server tag is not well formed.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24204203
This is really getting awkward now. Why dont you use the HyperLinkField instead.
0
 

Author Comment

by:spaceneedlejumper
ID: 24204216
CodeCruiser:

I'm sorry.  I've got to quit working on that.  I am presenting this site in 4 hours and I have other things that I'm actually making progress on that need work.

Thank you VERY MUCH for all of your help!
0
 

Author Comment

by:spaceneedlejumper
ID: 24204252
I tried the Hyperlink field for a long time like we've been doing with this.  The problem is that with the hyperlink field I run into problems something like, "onclick or onclientclick are not properties of such and such."  It has to do something with the combination of the gridview, onclick, hyperlink fields not having certain properties when they are in a gridview as opposed to when they aren't in one.

I've been on this one problem for probably at least ten hours over the last few weeks, just to get a confirm before deleting a record.

I wish I knew what to do.  There has got to be a reasonable way to do it.
0
 

Author Comment

by:spaceneedlejumper
ID: 24204301
If you'd like to try out working with the files themselves, I would be willing to give you FTP access to the production server.  
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24204566
I am at work so would not be able to do that.
0
 

Author Comment

by:spaceneedlejumper
ID: 24204592
You're far too generous even to consider it.  Thank you very much for all your efforts!  I'll figure something out.  Everything else works.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24204784
I wish i had a solution. Best of luck.
0
 

Author Closing Comment

by:spaceneedlejumper
ID: 31573036
Code Cruiser was extremely helpful, however, none of the solutions worked.  The question has been open for 2.5 months so I'm closing it.  Thanks, CC.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 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