Click here to Skip to main content
12,350,451 members (24,750 online)
Rate this:
 
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 11:36am
M S RAM268
Edited 12-Jan-13 15:44pm
v4
Comments
Sergey Alexandrovich Kryukov 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 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2016
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