简体   繁体   English

创造<input>使用 type=&quot;image&quot; 重定向到另一个带有参数的 aspx 页面

[英]Creating <input> with type="image" which redirects to another aspx page with arguments

Thanks to all of the help stackoverflow has been, I'm a new programmer and this site has been probably the best resource!感谢 stackoverflow 的所有帮助,我是一名新程序员,这个站点可能是最好的资源!

I'm using vb.net to dynamically make a datatable, which is bound to a gridview and populated into a placeholder on my aspx page.我正在使用 vb.net 动态制作一个数据表,该数据表绑定到 gridview 并填充到我的 aspx 页面上的占位符中。 I would like each cell to have an image with an onclick method, which passes a session variable to the next aspx page.我希望每个单元格都有一个带有 onclick 方法的图像,该方法将会话变量传递给下一个 aspx 页面。 I've tried making an input statement, where my DataRows are set individually like this:我试过做一个输入语句,其中我的 DataRows 是这样单独设置的:

DataRow(0) = "<input type='image' src='img.jpg' runat='server' onclick='NavigateToPage(NextPage.aspx)'>"

In my Chrome debug it is telling me my function is not within the scope that I'm calling it, so I tried making a javascript function on my .aspx page like this:在我的 Chrome 调试中,它告诉我我的函数不在我调用它的范围内,所以我尝试在我的 .aspx 页面上创建一个 javascript 函数,如下所示:

<script type='text/javascript'>
function NavigateToPage(page) {
    window.location.href = (page);
}

But still no redirect!但仍然没有重定向! Thanks in advance for the replies during the holiday season.提前感谢您在假期期间的回复。

Create a var for "page".为“页面”创建一个变量。 Try putting it in the global scope.尝试将其放在全局范围内。 If you are worried about polluting the global, then namespace your function and put the var in your function.如果你担心污染全局,那么命名你的函数并将 var 放在你的函数中。 Also put your page string in quotes.还将您的页面字符串放在引号中。

After some trial and error, I figured out how to set it up with a querystring:经过反复试验,我想出了如何使用查询字符串进行设置:

DataRow(0) = "<A href='NextPage.aspx'/><IMG src='img.jpg' Border=0>"

And of course put arguments for the NextPage using an href like this:当然,使用这样的 href 为 NextPage 放置参数:

href='Nextpage.aspx?value1='1'&value2='2'&value3='3'

i forgot to add initially that I have a small function at the end that decodes the text string into an html element after the table is bound to the gridview:我最初忘记补充一点,我在最后有一个小函数,可以在表绑定到 gridview 后将文本字符串解码为 html 元素:

    For i As Integer = 0 To gv.Rows.Count - 1
        For ColNo As Integer = 3 To 6
            gv.Rows(i).Cells(ColNo).Text = Context.Server.HtmlDecode(gv.Rows(i).Cells(ColNo).Text)
        Next
    Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM