Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Datafield Information ...

Status
Not open for further replies.

MojoZig

Technical User
Sep 27, 2005
61
US
Got and Issue ... New VS2005 User ...

I have this code which works great except:


Code:
  <div style="text-align:center;">
    <hr style="width:75%" />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=ServerName;User ID=UserName" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [TableName] WHERE ([Cust_ID] = @Cust_ID)" EnableCaching="True">
        <SelectParameters>
            <asp:ControlParameter ControlID="txtCust_ID" Name="Cust_ID" PropertyName="Text" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    
    <table>
        <tr>
            <td>
                Please Input your Account Number:
            </td>
            <td>
                <asp:TextBox ID="txtCust_ID" runat="server" MaxLength="10"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <asp:Button ID="Button1" runat="server" Text="Search for your Account Information!" />
            </td>
        </tr>
    </table>
    
    <br />
      <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" BackColor="White"
          BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataSourceID="SqlDataSource1"
          ForeColor="Black" GridLines="Vertical" Height="50px">
          <FooterStyle BackColor="#CCCC99" />
          <EditRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
          <RowStyle BackColor="#F7F7DE" />
          <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
          <Fields>
              <asp:BoundField DataField="Cust_Name" HeaderText="Customer Name" SortExpression="Cust_Name" />
              <asp:BoundField DataField="Cust_ID" HeaderText="Account Number" SortExpression="Cust_ID" />
              <asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
          </Fields>
          <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
          <AlternatingRowStyle BackColor="White" />
      </asp:DetailsView>
      
      <br />
      <br />    

       <asp:HiddenField ID="ClientID" runat="server" Value="66665555" />
       <asp:HiddenField ID="Password" runat="server" Value="55556666" />
       <asp:HiddenField ID="emailConfirmation" runat="server" Value="true" />
       <asp:HiddenField ID="PaymentFor" runat="server" Value="Oue Business Name" />
       <asp:HiddenField ID="UName" runat="server" Value="UNameInfo" />
       <asp:HiddenField ID="Redirect" runat="server" Value="[URL unfurl="true"]http://www.ourbusiness.com"[/URL] />
       
       <asp:Button ID="FullButton" runat="server" EnableViewState="False" Text="Click here to make a FULL payment!" PostBackUrl="[URL unfurl="true"]https://www.paymentportalsite.com/onlinepayment/redirect"[/URL] />


  </div>

Now, Everything mostly works just fine ... The SQL Database gets connected to properly, the input from the textbox is run in the query and the proper data is returned in a DetailView.

The detail view shows this information all packaged up nice and neatly:


Code:
<Fields>
<asp:BoundField DataField="Cust_Name" HeaderText="Customer Name" SortExpression="Cust_Name" />
<asp:BoundField DataField="Cust_ID" HeaderText="Account Number" SortExpression="Cust_ID" />
<asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
</Fields>

The problem I'm having is trying to get the information from these three fields above, as well as the hidden fields that follow them passed via the submit button.

I had a hidden field for each of the 3 returned BoundFields above but wasn't sure how to write the VB to say:
"HiddenField1's Value is EQUAL to BoundField's Value which was returned from the database."

I am thinking that I could write it in the VB file attached to my ASPX page ... Can I just submit the information right from the boundfields ... Does anybody have any thoughts?

The old way was familar, I used VBScript and an ASP Form to submit the information.


Question #2:
Is there a way to keep the second button hidden until after the first search button is clicked? Kind of like how the DetailView doesn't display until after the search button is clicked ...

Thanks,
MojoZig
 
What do you want to do with the values on the submit of the page? In ASP.NET, the page is posted to itself by default so you can easily grab the values. Or do you want to pass the values to another page?
 
JBenson,
(We have a JBenson here at work ... You are not alone!)
Anyway, I would like all the values of the boundfields AND the values of the hiddenfields submitted to the link on the submit button:

Code:
 <asp:Button ID="FullButton" runat="server" EnableViewState="False" Text="Click here to make a FULL payment!" PostBackUrl="[URL unfurl="true"]https://www.paymentportalsite.com/onlinepayment/redirect"[/URL] />

I don't know if that's the correct way since I used to use the <form action="thelink"> way before. Now it's just a little different! Postback on the button doesn't seem correct to me.


So, to recap: My connection works, my detailsview works all I need to do is port the values in the boundfields and hiddenfields to the link on the submit button.

I really appreciate your time.

Thanks,
MojoZig
 
I'm not sure if you could change the PostBackURL to add the querystring varialbes without having to click the button twice. You can pass the values you need to the next page using session variables.

Jim
 
Well, I found that I can populate the HiddenField Values via the CodeBehind page when the button1 is clicked:

Code:
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim AccountID As String = Request.Form("Cust_ID")
        Dim CustNameID As String = Request.Form("Cust_Name")
        Dim AmountID As String = Request.Form("Amount")

        AccountNo.Value = "AccountID"
        CustName.Value = "CustNameID"
        Amount.Value = "AmountID"

    End Sub

Only problem is, the values end being:

Code:
      <input type="hidden" name="ctl00$ContentPlaceHolder1$AccountNo" id="ctl00_ContentPlaceHolder1_AccountNo" value="AccountID" />
      <input type="hidden" name="ctl00$ContentPlaceHolder1$CustName" id="ctl00_ContentPlaceHolder1_CustName" value="CustNameID" />
      <input type="hidden" name="ctl00$ContentPlaceHolder1$Amount" id="ctl00_ContentPlaceHolder1_Amount" value="AmountID" />

Obviously not the data from the database that is displayed in my gridview ...
It's not even getting the information from the Dim Variable either since I can do:

Code:
      Dim AccountID As String = ("TestText")
      AccountNo.Value = "AccountID"

The value is changed to AccountID, not the string TestText.

Since the AccountNo.Value = "AccountID" seems to populate the value, I've tried other ways like:

Code:
AccountNo.Value = Request.Form("Cust_ID")

and

Code:
AccountNo.Value = Gridview1.Cust_ID

Does anybody have any further thoughts on how to get the hidden values populated with the information coming from the GridView???

Thanks,
MojoZig
 
It's not even getting the information from the Dim Variable either since I can do:

Dim AccountID As String = ("TestText")
AccountNo.Value = "AccountID"

The value is changed to AccountID, not the string TestText.
That's because you declare a variable, set it's contents to a string of "TestText", then you change it to a string which is "AccountID".

Without being condesending, you really need to read up on the basics of ASP.NET and variables in general as this is pretty much day 1 stuff. Once you've got a grasp on that, then I'd go back to your problem.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks for the information but the code you quote above is being used only to see if I can even get the text "TestText" to pass to the hiddenfield value which it doesn't. Has nothing really to do with with the data from the database. I was bypassing the database to see if the dim variable would get passed. Troubleshooting. I'm certainly not a programmer, but this code on the buttons codebhind page:

Code:
      Dim AccountID As String = ("TestText")
      AccountNo.Value = "AccountID"


Should pass, at least I would think it should, "TestText" to the hiddenfield's value. Which is why I posted this here since obviously I must be incorrect, confused or just slightly off.

Anyway, thanks again.

No disrespect intended.

MZ

 
Dim AccountID As String = ("TestText")
AccountNo.Value = "AccountID"

Should pass, at least I would think it should, "TestText" to the hiddenfield's value.
No, it shouldn't. The example above should pass a String with a value "AccountID" through to the AccountNo control (which you say is a Hidden field).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Your right, I had the "" around it and it was getting passed as you stated. My bad. Why don't you just say, "Remove the quotes and the information will get passed."?? I really appreciate you schooling me on the string. :)

AccountNo is a hiddenfield and I noticed I left them out of the code at the top of this post. Sorry, I was moving a lot of stuff around. There are 3 hiddenfields that are:

Code:
<asp:HiddenField ID="AccountNo" runat="server" Value="" />
      <asp:HiddenField ID="CustName" runat="server" Value="" />
      <asp:HiddenField ID="Amount" runat="server" Value="" />

I guess that would help, huh?

So, now that I am getting the test string passed through the very simple code above, how do I get the database data from the boundfields?

I would think that I would be able to Dim the variables and request.form the fields being posted to the boundfields as such:

Code:
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim AccountID As String = Request.Form("Cust_ID")
        Dim CustNameID As String = Request.Form("Cust_Name")
        Dim AmountID As String = Request.Form("Amount")

        AccountNo.Value = AccountID
        CustName.Value = CustNameID
        Amount.Value = AmountID

    End Sub


Or just populate them by something like this example (which I do know is incorrect):

Code:
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        AccountNo.Value = GridView1.DataSourceID.Cust_ID

    End Sub

Or something like that. Certainly it's that easy ... Thoughts?

MZ
 
Thanks for the help, I figured it out:

The key information was gained from an MSDN TV show that showed how to use a DataList vs using the GridView or Details view. In the DataList, you can drag controls such as the HiddenFields and assign them a database field. I did have one problem though, I couldn't call the HiddenFields information by the name of the field, I had to call it by what ASP.Net converted it to in the source for some reason such as the field:

Code:
<asp:HiddenField ID="HFAccount" runat="server" Value='<%# Eval("Account") %>' />

Couldn't be grabbed by using the ID of HFAccount but rather had to grab it by the name of "DataList1$ctl00$HFAccount".

If anybody can explain that I would be most appreciative!

I used Server.URLEncode and Server.URLDecode's to post the data via a querystring since it had spaces in the data and wouldn't pass. I grabbed the querystring information as such:

Code:
Dim AccountID As String = Server.UrlDecode(Request.QueryString("AccountID"))


Another thing that I was perplexed about was the single querystring was passed as:

Code:
Response.Redirect("OEUPost2.aspx?AccountID=" & AccountID.ToString())

But when I passed multiple values I had to leave off the ".ToString()" after each of the variables.

Code:
Response.Redirect("OEUPost3.aspx?PaymentID=" & Server.UrlEncode(PaymentID) & "&AccountID=" & Server.UrlEncode(AccountID) & "&NameID=" & Server.UrlEncode(NameID) & "&AmountID=" & Server.UrlEncode(AmountID))

Again, if anybody cares to explain that, I would like to hear it!

Anyway, I still think there has to be a better way than how I did it but it seems to work really well. It took three pages to step through the process ... Get the Account Info>Display the Account, get payment info>Display the payment info and the verify button used VB to Response.Write my old form submission to the external CFServer. I couldn't figure out how to submit the data to the external coldfusion server without it freaking out on the auto-generated fields asp.net uses such as the hidden fields it would post with _EVENTARGUMENTS or whatever they were.

So anyway, in case anybody was wondering or was looking for a similar solution to a similar problem, use the datalist and drag and drop the hiddenfields in there. It will prompt you to bind the attributes to data in the database.

I still think there is a way to just assign the hiddenfield values directly from the boundfields in a gridview but this was easier.

The TV Show was at:

Sincerely,
MojoZig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top