Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a URL in HTML with Text Box Values

Tags:

html

c#

I am adding a button to my website that will take the user to a website and fill in various variables from text boxes on my site.

Here is the markup code from my HTML Page:

<body>
<form id="form1" runat="server">
<div>

    <asp:Label ID="FirstNameLabel" runat="server" Text="First Name:" Width="100px"></asp:Label>
    <asp:TextBox ID="FirstNameTxtBox" runat="server" Width="150px"></asp:TextBox>
    <br />
    <asp:Label ID="LastNameLabel" runat="server" Text="Last Name:" Width="100px"></asp:Label>
    <asp:TextBox ID="LastNameTextBox" runat="server" Width="150px"></asp:TextBox>
    <br />
    <asp:Label ID="EmailLabel" runat="server" Text="E-mail Address:" Width="100px"></asp:Label>
    <asp:TextBox ID="EMailTextBox" runat="server" Width="150px"></asp:TextBox>

    <br />
    <asp:Label ID="DescLabel" runat="server" Text="Description:" Width="100px"></asp:Label>
    <asp:TextBox ID="DescTextBox" runat="server" Height="100px" Width="150px"></asp:TextBox>

</div>
    <button class="button" style="height:20px;width:120px" onclick="<%# String.Format("location.href='https://biznetsoftware.fastsupport.com/?first_name={0}&last_name={1}&email={2}&question=   {3}",FirstNameTxtBox.Text,LastNameTextBox.Text,EMailTextBox.Text,DescTextBox.   Text) %>" id="JoinChatButton">Join Chat</button>


</form>
</body>

The page doesn't go to the destination URL. What am I doing wrong?

like image 245
CSammons Avatar asked Dec 09 '25 17:12

CSammons


1 Answers

You can use this code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script runat="server">
    void JoinChat(Object sender, EventArgs e)
    {
        string url = String.Format("https://biznetsoftware.fastsupport.com/?first_name={0}&last_name={1}&email={2}&question={3}", 
                    FirstNameTxtBox.Text,
                    LastNameTextBox.Text,
                    EMailTextBox.Text,
                    DescTextBox.Text); 
         Response.Redirect(url);
    }
    </script>
</head>
<body>
<form id="form1" runat="server">
<div>

    <asp:Label ID="FirstNameLabel" runat="server" Text="First Name:" Width="100px"></asp:Label>
    <asp:TextBox ID="FirstNameTxtBox" runat="server" Width="150px"></asp:TextBox>
    <br />
    <asp:Label ID="LastNameLabel" runat="server" Text="Last Name:" Width="100px"></asp:Label>
    <asp:TextBox ID="LastNameTextBox" runat="server" Width="150px"></asp:TextBox>
    <br />
    <asp:Label ID="EmailLabel" runat="server" Text="E-mail Address:" Width="100px"></asp:Label>
    <asp:TextBox ID="EMailTextBox" runat="server" Width="150px"></asp:TextBox>

    <br />
    <asp:Label ID="DescLabel" runat="server" Text="Description:" Width="100px"></asp:Label>
    <asp:TextBox ID="DescTextBox" runat="server" Height="100px" Width="150px"></asp:TextBox>

</div>
    <asp:Button class="button" style="height:20px;width:120px" id="JoinChatButton" Text="Join Chat" runat="server"OnClick="JoinChat" />

</form>
</body>
</html>
like image 200
Zafer Ayan Avatar answered Dec 12 '25 05:12

Zafer Ayan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!