Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Gridview HTML5
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).
 
<asp:TemplateField>
    <ItemTemplate>
        <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=""/> 
                                        Edit
                                    </button>
        </div>
    </ItemTemplate>
</asp:TemplateField>
 

 
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 12:36pm
M S RAM268
Edited 12-Jan-13 16:44pm
v4
Comments
Sergey Alexandrovich Kryukov at 12-Jan-13 19:52pm
   
ASP.NET? Add a tag "ASP.NET"...
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try:
onclick="buttonClick('0')" 
 
function buttonClick(tID)
{
   window.location.href='TemplateEdit.aspx?TemplateId='+tID;
   return false;
}
  Permalink  
Comments
M S RAM at 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 = "www.gmail.com"; //"TemplateEdit.aspx?TemplateId=" + TemplateId + "&UserName=" + UserName;
return false;
}
</script>
Sandeep Mewara at 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
good
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.
 
Ram
  Permalink  

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

  Print Answers RSS
0 Maciej Los 495
1 Sergey Alexandrovich Kryukov 469
2 OriginalGriff 360
3 Sascha Lefévre 255
4 Abhinav S 250
0 Sergey Alexandrovich Kryukov 10,102
1 OriginalGriff 9,495
2 Peter Leow 5,241
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,076


Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2015
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