PDA

View Full Version : Set value inline



Nime
Nov 03, 2009, 9:06 AM
I need to set an AJAX parameter inline. I tried a few things but no luck.


Value="#this.memberID"
Value="#memberID"
Value="#{memberID}"

ie...

I want to click a button then refresh the form data with query string value as ID. What is the proper way to to that?


<ext:Button ID="btnRefresh" runat="server" Text="Refresh" Icon="ArrowRefresh">
<AjaxEvents>
<Click OnEvent="Refresh" Buffer="250">
<EventMask ShowMask="true" MinDelay="250" Msg="Refreshing..." />
<ExtraParams>
<ext:Parameter Name="memberID" Value="#{memberID}" />
</ExtraParams>
</Click>
</AjaxEvents>
</ext:Button>

public static int memberID = 0;

protected void Page_Load(object sender, EventArgs e)
{
try { memberID = Convert.ToInt16(Request.QueryString["memberID"]); } catch { }
}

protected void Refresh(object sender, AjaxEventArgs e)
{
string memberID = e.ExtraParams["memberID"];
...

}

Vladimir
Nov 03, 2009, 9:20 AM
Hi,

You can use any javascript code in Value. For example, you can save required value in hidden field and retrieve hidden field value in ExtraParameter:

<ext:Parameter Name="memberID" Value="Hidden1.getValue()" Mode="Raw" />

Nime
Nov 03, 2009, 9:58 AM
Is it possible to insert any server side value instead of clientside? May I embed memberID at runtime?



Coolite: <ext:Parameter Name="geziID" Value=""<%=this.geziID%>" /> code generates Ext.js code like below:


extraParams:{"geziID":"<%=this.geziID%>"}




I think Coolite cannot process any response.write shorthand code.

Vladimir
Nov 03, 2009, 10:08 AM
Hi,

You can always use codebehind to set what you need

btnRefresh.AjaxEvents.Click.ExtraParams[0].Value = memberId;


Also I am not test it but try the following (use # instead = and set AutoDataBind="true")

<ext:Parameter Name="geziID" Value="<%# this.geziID %>" AutoDataBind="true" />

Nime
Nov 03, 2009, 10:14 AM
Hmmm, now I'm in a very strange situation. I used a hidden field, set it in page load but

e.ExtraParams["memberID"] returns "hidMemberID.getValue()" in ajax event's function Refresh


Why Coolite cannot generate the correct JS here? Did I miss anything?

Vladimir
Nov 03, 2009, 10:18 AM
Hi,

Because you have to set Mode="Raw"


Value mode - wraps by quotes
Raw mode - without quotes

Nime
Nov 03, 2009, 10:21 AM
Thany you for quick responses. With AutoDataBind = true, I got the memberID too.

mrozik
Apr 21, 2010, 7:23 AM
Hi!
I have the same problem when trying to set store page size:



<AutoLoadParams>
<ext:Parameter Name="start" Value="={0}" />
<ext:Parameter Name="limit" Value="={<%#PageSize%>}" AutoDataBind="true"/>
</AutoLoadParams>


but JS 'syntax error occures' - in page source I see:



autoLoad:{params:{"start":0,"limit":<%#PageSize%>}}});

Vladimir
Apr 21, 2010, 8:05 AM
Hi,

You cannot wrap '<%# %>'. The following should work

Value="<%# PageSize %>"


But with '={}' it will not work, ASP.NET parser doesn't support it
You don't need '={}', just set Mode="Raw"



<ext:Parameter Name="limit" Value="<%#PageSize%>" Mode="Raw" AutoDataBind="true"/>

mrozik
May 05, 2010, 10:27 AM
Thanks for solution!