Click here to Skip to main content
12,952,159 members (58,270 online)
Rate this:
Please Sign up or sign in to vote.
Hi, I want to use a html5 button tag in the gridview item template. But none of the events/redirection that I write onclick of the button doesn't work (Both server & client).

        <div class="buttons"> <!-- onEditClick('<%#Eval("TemplateId") %>','<%#Request.QueryString["UserName"] %>')  -->
                                    <button id="btnEditTemplate" class="positive" onclick="window.location.href='TemplateEdit.aspx?TemplateId=0'" >
                                        <img src="./styles/ico_edit.png" alt=""/> 

In case of a server side event, then I need to get the instance of that button clicked in the gridview command, to get appropriate row clicked.

Any help would be much appreciated.
Posted 12-Jan-13 11:36am
M S RAM284
Updated 12-Jan-13 15:44pm
Sergey Alexandrovich Kryukov 12-Jan-13 19:52pm
ASP.NET? Add a tag "ASP.NET"...
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


function buttonClick(tID)
   return false;
M S RAM 13-Jan-13 3:25am
Hi Sandeep, Many thanks for you help, I tried that too, but the function just submits to the same page i guess, nothing else happens. This is what happens in the function, the alert gets fired, but not the redirect. Thanks in advance for your time.

<script type="text/javascript">
function onEditClick(TemplateId, UserName) {
alert("TemplateEdit.aspx?TemplateId=" + TemplateId + "&UserName=" + UserName)
window.location.href = ""; //"TemplateEdit.aspx?TemplateId=" + TemplateId + "&UserName=" + UserName;
return false;
Sandeep Mewara 13-Jan-13 3:27am
So, your next steps are to check if url is correct or not. Then if needed, use windows.navigate in order to go to that page.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Thanks a lot Sandeep, I have managed to fix it. The javascript is expecting the complete url in the location.href. Many thanks for your time, much appreciated.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100