1

I am using asp.net c# with x-jquery-tmpl

So I am attempting to pass data to the code behind. I am generating a range of divs, based on some data, and assigning the name/values of the div using a template.

The problem I am having is that when the information is passed it is shown in the jquery form, and not showing the actual value.

     <script id="SomeTemplate" type="text/x-jquery-tmpl">
        <div class="grid_12">
        <div class="box">
        <div class="header">
        <img alt="img" width="16" height="16" />
                    <h3>Title: ${text}</h3>
                    <div class="box" style="float:right; margin-top: -4px; margin-right: 8px" >
                        <asp:Button id="btn${text}" Text="${text}" runat="server" OnClick="RedirectPage" CommandArgument=${text} style="vertical-align:middle"/>
                    </div>
                </div>
                <div class="content">
                    <canvas id="cvs${text}" width="1600" height="750" style="border: 1px solid #222;">[No canvas support]</canvas>
                </div>
            </div>
    </div>
</script>

When the button is clicked the behind code is executed:

protected void RedirectPage(object sender, EventArgs e)
    {
        Button test = (Button)sender;
        string t = test.CommandArgument.ToString(); // returns $(text)
        Response.Redirect("http://www.address.com/" + t);
    }

The problem is that I want to use the value passed as part of my redirect.

Any help would be very much appreciated.

Thank you

Marten2009
  • 89
  • 10
  • 1
    Not sure it is a good idea to have an asp.net server control in a jstemplate Maybe you should switch to regular button input which would invoke __dopostback see for example http://stackoverflow.com/questions/3591634/how-to-use-dopostback – jbl Nov 12 '13 at 16:08
  • good, you may now accept your own answer – jbl Nov 12 '13 at 16:50

1 Answers1

1

I have swapped out:

<asp:Button id="btn${text}" Text="${text}" runat="server" OnClick="RedirectPage" CommandArgument=${text} style="vertical-align:middle"/>

for:

<input type="button" id="btnSave" onclick="javascript:redirectPage('${text}')" value="click me"/>

I could then use the __doPostBack and handle this on the page load side. more details can be found in How to use dopostback.

thanks to @jbl for pointing me in the right direction

Community
  • 1
  • 1
Marten2009
  • 89
  • 10