Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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).

XML
<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
Updated 12-Jan-13 15:44pm
v4
Comments
Sergey Alexandrovich Kryukov 12-Jan-13 19:52pm    
ASP.NET? Add a tag "ASP.NET"...
—SA

Try:
HTML
onclick="buttonClick('0')" 


JavaScript
function buttonClick(tID)
{
   window.location.href='TemplateEdit.aspx?TemplateId='+tID;
   return false;
}
 
Share this answer
 
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.
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900