在html标记中将文本框值作为查询字符串传递 [英] pass textbox value as querystring in html a tag

查看:72
本文介绍了在html标记中将文本框值作为查询字符串传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个asp.net网站。我是这个IT世界的新手。

我有一个列表视图,其中包含一个图像和一个类别的标签。我将这些项目包装在 标记中,这样每当用户点击其中任何一个控件时,它都会重定向到另一个页面。在列表视图之外,我有一个包含城市名称的ajax组合框。它在页面加载时有一个选定的值。

现在,只要用户点击列表视图中的任何一个图像或标签,它就会重定向到包含城市和类别名称的查询字符串值的SubCat.aspx页面。 />
此查询字符串将在a href =页面中传递?查询字符串



我的问题是我无法获得aspx页面中标记中的组合框值。我知道如何从代码后面传递查询字符串。



或者无论如何都要将查询字符串的值放在aspx.cs页面中然后检索它在aspx页面的a标签中?



谢谢。



aspx代码:< br $> b $ b

 <   head  >  
< 脚本 >
$( document ).ready( function (){
var _cityId = $(' #ComboBox1')。val();
var url = http://google.com?cityid= + _cityId;
$( span)。on( 点击 function (){
window location .href = url;
});
});
< / script >
< / head >

< 正文 >

< asp:ComboBox ID = ComboBox1 runat = server AutoCompleteMode = SuggestAppend DataSourceID = < span class =code-keyword> SqlDataSource1

< span class =code-attribute> < span class =code-attribute> DataTextField = city AutoPostBack = True DataValueField = city OnSelectedIndexChanged = ComboBox1_SelectedIndexChanged

< span class =code-attribute> MaxLength = 0 样式 = display:inline; >
< asp:ListItem > ---选择城市--- < / asp:ListItem >
< / asp:ComboBox >

< asp:ListView ID = ListView1 GroupItemCount = 3 GroupPlaceholderID = ContactRowContainer

ItemPlaceholderID = ContactItemContainer runat = server >
< LayoutTemplate >
< table cellpadding = 50 width = 600px runat = server id = tblContacts >
< tr id = Tr1 runat = 服务器 >
< / tr >
< tr runat = 服务器 id = ContactRowContainer / >
< / table >
< br / >

< / LayoutTemplate >
< GroupTemplate >
< tr runat = server < span class =code-attribute>
id = ContactRow >
< td runat = server id = ContactItemContainer / >
< / tr >
< / GroupTemplate >
< ItemTemplate >
< td runat = server id = Td1 < span class =code-attribute> align = center >
<% - < ; a href =User / SubCat.aspx?cid =<%#Eval(cat_name)%>> - %>
< span >
< asp:Image ID = Image1 runat = 服务器 宽度 = 100 高度 = 100 ImageUrl =' <%# Eval( image)%>' / >
< asp:标签 ID = Label1 runat = server 文本 =' <% #Eval( cat_name)%>' > < < span class =code-leadattribute> / asp:Label > < / span >
< / td >
< / ItemTemplate >
< / asp:ListView > ;

< / body >

解决方案

document ).ready( function (){
var _cityId =


' #ComboBox1')。val();
var url = http:// google.com?cityid = + _cityId;


span)。on( 点击 function (){
window location .href = url ;
});
});
< / script >
< / head >

< 正文 >

< asp:ComboBox ID = ComboBox1 runat = server AutoCompleteMode = SuggestAppend DataSourceID = < span class =code-keyword> SqlDataSource1

< span class =code-attribute> < span class =code-attribute> DataTextField = city AutoPostBack = True DataValueField = city OnSelectedIndexChanged = ComboBox1_SelectedIndexChanged

< span class =code-attribute> MaxLength = 0 样式 = display:inline; >
< asp:ListItem > ---选择城市--- < / asp:ListItem >
< / asp:ComboBox >

< asp:ListView ID = ListView1 GroupItemCount = 3 GroupPlaceholderID = ContactRowContainer

ItemPlaceholderID = ContactItemContainer runat = server >
< LayoutTemplate >
< table cellpadding = 50 width = 600px runat = server id = tblContacts >
< tr id = Tr1 runat = 服务器 >
< / tr >
< tr runat = 服务器 id = ContactRowContainer / >
< / table >
< br / >

< / LayoutTemplate >
< GroupTemplate >
< tr runat = server < span class =code-attribute>
id = ContactRow >
< td runat = server id = ContactItemContainer / >
< / tr >
< / GroupTemplate >
< ItemTemplate >
< td runat=\"server\" id=\"Td1\" align=\"center\">
<%-- <a href=\"User/SubCat.aspx?cid=<%#Eval(\"cat_name\") %>\">--%>
<span>
<asp:Image ID=\"Image1\" runat=\"server\" Width=\"100\" Height=\"100\" ImageUrl='<%#Eval(\"image\") %>' />
<asp:Label ID=\"Label1\" runat=\"server\" Text='<%#Eval(\"cat_name\") %>'></asp:Label></span>
</td>
</ItemTemplate>
</asp:ListView>

</body>


I am building an asp.net website. I am new to this IT world.
I have a list view which contains a image and a label of the Category. I am wrapped these items in tag, so that whenever the user click in any of these controls it will redirect to another page. Outside the list view i have an ajax combo box which contains city names. It has a selected value on page load.
Now whenever a user clicks on either image or label inside list view it will redirect to page SubCat.aspx with query string values containing city and category name.
This query string will be passed in "a href="page?query string""

My problem is that i am not able to get the combo box value in a tag in aspx page. I know how to pass query string from code behind.

or is there anyway to put the values of querystring or form the query string in aspx.cs page and then retrieve it in "a" tag in aspx page?

Thank you.

code of aspx:

<head>
<script>
    $( document ).ready(function() {
    var _cityId = $('#ComboBox1').val();
    var url = "http://google.com?cityid=" + _cityId;
    $( "span" ).on( "click", function() {
        window.location.href = url;
    });
});
</script>
</head>

<body>

 <asp:ComboBox ID="ComboBox1" runat="server" AutoCompleteMode="SuggestAppend" DataSourceID="SqlDataSource1"

                                            DataTextField="city" AutoPostBack="True" DataValueField="city" OnSelectedIndexChanged="ComboBox1_SelectedIndexChanged"

                                            MaxLength="0" Style="display: inline;">
                                            <asp:ListItem>---Select City---</asp:ListItem>
                                        </asp:ComboBox>

<asp:ListView ID="ListView1" GroupItemCount="3" GroupPlaceholderID="ContactRowContainer"

                                    ItemPlaceholderID="ContactItemContainer" runat="server">
                                    <LayoutTemplate>
                                        <table cellpadding="50" width="600px" runat="server" id="tblContacts">
                                            <tr id="Tr1" runat="server">
                                            </tr>
                                            <tr runat="server" id="ContactRowContainer" />
                                        </table>
                                        <br />
                                      
                                    </LayoutTemplate>
                                    <GroupTemplate>
                                        <tr runat="server" id="ContactRow">
                                            <td runat="server" id="ContactItemContainer" />
                                        </tr>
                                    </GroupTemplate>
                                    <ItemTemplate>
                                        <td runat="server" id="Td1" align="center">
                                         <%--   <a href="User/SubCat.aspx?cid=<%#Eval("cat_name") %>">--%>
                                         <span>
                                                <asp:Image ID="Image1" runat="server" Width="100" Height="100" ImageUrl='<%#Eval("image") %>' />
                                                <asp:Label ID="Label1" runat="server" Text='<%#Eval("cat_name") %>'></asp:Label></span>
                                        </td>
                                    </ItemTemplate>
                                </asp:ListView>

</body>

解决方案

( document ).ready(function() { var _cityId =


('#ComboBox1').val(); var url = "http://google.com?cityid=" + _cityId;


( "span" ).on( "click", function() { window.location.href = url; }); }); </script> </head> <body> <asp:ComboBox ID="ComboBox1" runat="server" AutoCompleteMode="SuggestAppend" DataSourceID="SqlDataSource1" DataTextField="city" AutoPostBack="True" DataValueField="city" OnSelectedIndexChanged="ComboBox1_SelectedIndexChanged" MaxLength="0" Style="display: inline;"> <asp:ListItem>---Select City---</asp:ListItem> </asp:ComboBox> <asp:ListView ID="ListView1" GroupItemCount="3" GroupPlaceholderID="ContactRowContainer" ItemPlaceholderID="ContactItemContainer" runat="server"> <LayoutTemplate> <table cellpadding="50" width="600px" runat="server" id="tblContacts"> <tr id="Tr1" runat="server"> </tr> <tr runat="server" id="ContactRowContainer" /> </table> <br /> </LayoutTemplate> <GroupTemplate> <tr runat="server" id="ContactRow"> <td runat="server" id="ContactItemContainer" /> </tr> </GroupTemplate> <ItemTemplate> <td runat="server" id="Td1" align="center"> <%-- <a href="User/SubCat.aspx?cid=<%#Eval("cat_name") %>">--%> <span> <asp:Image ID="Image1" runat="server" Width="100" Height="100" ImageUrl='<%#Eval("image") %>' /> <asp:Label ID="Label1" runat="server" Text='<%#Eval("cat_name") %>'></asp:Label></span> </td> </ItemTemplate> </asp:ListView> </body>


这篇关于在html标记中将文本框值作为查询字符串传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆