Syntax to pass the value of a textbox from an edittemplate to a javascript function  
Author Message
kfrost





PostPosted: JScript for the .NET Framework, Syntax to pass the value of a textbox from an edittemplate to a javascript function Top

I have a grid with the columns section as follows:

<Columns>

<radG:GridBoundColumn DataField="LevelID" HeaderText="ID" UniqueName="LevelID" Visible="False">

</radG:GridBoundColumn>

<radG:GridTemplateColumn HeaderText="Level Name" UniqueName="TemplateColumn">

<ItemTemplate>

<asp:Label ID="txtLevelName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LevelName") %>'></asp:Label>

</ItemTemplate>

<EditItemTemplate>

<asp:TextBox ID="txtLevelName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LevelName") %>'></asp:TextBox>

</EditItemTemplate>

</radG:GridTemplateColumn>

<radG:GridTemplateColumn UniqueName="TemplateColumn">

<ItemTemplate>

<asp:ImageButton runat="server" ImageUrl="/RadControls/Grid/Skins/Default/Edit.gif" CausesValidation="true" CommandName="Edit" AlternateText="Edit" />

</ItemTemplate>

<EditItemTemplate>

<asp:ImageButton ID="iEdit" runat="server" ImageUrl='<%# ((bool)DataBinder.Eval(Container, "OwnerTableView.IsItemInserted")) "/RadControls/Grid/Skins/Default/Insert.gif" : "/RadControls/Grid/Skins/Default/Update.gif" %>' CommandName='<%# ((bool)DataBinder.Eval(Container, "OwnerTableView.IsItemInserted")) "PerformInsert" : "Update" %>' AlternateText="Ok" />&nbsp;

<asp:ImageButton runat="server" ImageUrl="/RadControls/Grid/Skins/Default/Cancel.gif" CausesValidation="false" CommandName="Cancel" AlternateText="Cancel" />

</EditItemTemplate>

</radG:GridTemplateColumn>

<radG:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ImageUrl="/RadControls/Grid/Skins/Default/Delete.gif"

Text="Delete" UniqueName="column" ConfirmText="Delete this record ">

<HeaderStyle Width="50px" />

</radG:GridButtonColumn>

</Columns>

For the iEdit image button I'm trying to find the syntax to use with an OnClientClick function to pass the ClientID of txtLevelName when the grid is in Edit mode The javascript function is as follows:

function ValidateControls(Id)

{

alert(Id);

var box = document.getElementById(Id);

if(box.value == "")

{

alert("Name cannot be empty!");

return false;

}

}

I have tried just passing the text value by using OnClientClick="ValidateControl('" + Eval("LevelName") + "')" or something like that but the problem is, it only returns the value of the textbox when the page was loaded. If somebody changes the text or if it were blank on load such as would be the case in the insert, that value is passed to the javascript function instead of what has just been typed in.

Trying to keep this short and sweet. If I need to add more details please advise.

With that being said, anybody have any idea for the syntax to pass the clientID of txtLevelName to ValidateControl(Id)

Thanks.




.NET Development9  
 
 
mtsonic





PostPosted: JScript for the .NET Framework, Syntax to pass the value of a textbox from an edittemplate to a javascript function Top

Just used your OnClientClick event and found that there might be a syntax problem. I have not tested it and am not that good a javascript... Might this be correct

OnClientClick="SetDraftFile('" + '<%# Eval("LinkToFile") %>' + "')"