Webforms postback with multiple arguments - asp.net

I wish to call the __doPostBack(eventTarget, eventArgument) function. In the code file I would then read the arguments as usual like this: Dim param As String = Request("__EVENTARGUMENT"). However this doesn't work for multiple arguments.
Someone here suggested that you could use a json or csv-list. Usually I would just choose a delimiter that sepeates my arguments. However in my case now the argument may contain any character, so I can't just decide on any delimiter, so I figured I'd use a JSON.
I tried this.
Markup:
<button type="button" id="btn_postbackButton" onclick="__doPostBack('btn_postbackButton', {one: 'someText', two: 'moreText'});">TestButton</button>
Code-File
If (IsPostBack) Then
Dim tgt As Object = Request("__EVENTTARGET")
Dim param As Object = Request("__EVENTARGUMENT") ' what datatype to use?
' [...]
' how to get arguments from json?
End If
Now how do I get my arguments back in the code? What datatype do I use for the parameters? Calling param.ToString() only returns [object Object]
What's more, the arguments are generated in the code file in my actual application, and there may be different ones and some may be missing, using a simple array doesn't work for me as you can't determine after the fact which array position coresponds to which argument. And regardless it still gives me [object Object].

When your button is clicked, the page sends the following HTML form fields:
__EVENTTARGET: btn_postbackButton
__EVENTARGUMENT: [object Object]
To get your json on the server side as a string, use the following button markup:
<button type="button" id="btn_postbackButton" onclick="__doPostBack('btn_postbackButton', '{one: \'someText\', two: \'moreText\'}');">TestButton</button>

Related

typeof equivalent of .NET for ABL Progress Openedge

I have added System.Messaging to my assemblies.xml cause I need to use this in my Progress OpenEdge application. However I ran into a problem.
In C# when assigning:
m.Formatter = new XmlMessageFormatter(new[] { typeof(TrowConfiguration) });
TrowConfiguration myConfiguration = m.Body as TrowConfiguration;
However I now want to do this in ABL. I first used a method to read a string and just passed a CHARACTER EXTENT 1 INITIAL "System.String" to the XmlMessageFormatter object. However I tried changing this to the path of my object, TrowConfiguration, but this doesn't work and gives me an error.
If you're looking for the System.Type reference, use
Progress.Util.TypeHelper:GetType ("<your fully qualified type name>").

pass request parameter value to class function and return value in classic asp

I am 3 days new to classic asp after a few years of .NET.
I have a simple form (consisting of radio buttons) that collects information and saves it to the a database (think basic survey form).
I get the following error when submitting the form:
Microsoft VBScript runtime error '800a01a8'
Object required: ''
/project/surveypage.asp, line 83
I have the following code on the survey page (snippet)
<%
Dim oConstants
Set oConstants = new Constants
Dim d1NumberOfFF
d1NumberOfFF = oConstants.GetValue(Request.Form("d1NumberOfFF")) '<--- line 83
%>
And the following class (Constants.asp):
<%
Class Constants
'..........
function GetValue(item)
GetValue = 99
If NOT IsEmpty(item) Then
GetValue = item
End if
end function
End Class
%>
It seems basic enough but is acting like the function doesn't exist or that I can't pass the Form value? Beginning to think I've been too babied by .NET
You say you cant pass a querystring value, and you're using Request.Form("d1NumberOfFF") on line 83.
Request.Form only captures form variables (ie from a form using method="post"), Request.Querystring is the equivalent for a querystring value, or you could just use Request and it would collect either kind of variable

Json.net escaping or removing a character on SerializeObject

I am using Mvc 4 with Json.Net. I have an error message property with the follong content on the server:
"'Instalation Name' should not be empty."
On the client I am doing something like this:
'#Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(this.Model, Newtonsoft.Json.Formatting.None, new Newtonsoft.Json.Converters.StringEnumConverter()))';
and the output is the following:
"ErrorMessage":"'Instalation Name' should not be empty."
which is throwing error:
Expected ';'
I need a way to escape or remove the ' character. How can I do this? One way is to do custom JsonConverter ... Any other suggestions? Thanks!
I guess your #Html.Raw() is placed within <script></script>. So I suggest you just remove the ' characters around your JSON, so it looks like this:
<script type="text/javascript">
var v = #Html.Raw(...);
</script>
So the the variable v will receive the deserialized data directly.

How to override VBScript GetObject method in .NET

I am having below code in VBScript
' Retrieve the keyword category for page section names
Set SectionCat = TDSE.GetObject(WebdavToUri(getPublicationWebDav(WEBDAV_SECTION_CAT)), 1)
' Retrieve the localized section keyword
Set SectionKeyword = SectionCat.GetKeywordByTitle(meta)
' Open the English translated section keyword
Set SectionKeyword = TDSE.GetObject(SectionKeyword.Id, 1, WEBDAV_UKEN_PUB)
SectionName = SectionKeyword.Title
Where WEBDAV_UKEN_PUB is the WebDavPath, now in VBScript GetObject method we have got option to pass three parameters 1) Item.ID, 2) TDSDefines.OpenModeEditWithFallback and 3) WebDavPath from where to make the object.
Now I want to write same logic in 2009 .Net templating, below is the sample code, I am trying to write but not able to get rid of VBScript Object.
Category cat = engine.GetSession().GetObject(WebdavToUri(getPublicationWebDav(Constants.WEBDAV_SECTION_CAT,package,engine), engine)) as Category;
if (cat != null)
{
//_log.Info("Category" + cat.Title);
Keyword keyword = cat.GetKeywordByTitle(meta);
//_log.Info("keyword 1" + keyword.Title);
keyword = engine.GetObject(Constants.WEBDAV_UKEN_PUB) as Keyword;
//_log.Info("keyword 2 " + keyword.Title);
if (keyword != null)
{
sectionName = keyword.Title;
}
keyword = null;
I am able to create Category object, however when I am trying to make Keyword object its getting failed and giving object reference error.
Do we have any class or method which work same like VBScript GetObject which will make the Object from the passed webdavpath or can somebody can give sample code on this.
I think your problem is here:
keyword = engine.GetObject(Constants.WEBDAV_UKEN_PUB) as Keyword;
You are using the WEBDav URL of a publication, and then attempting a dynamic cast to Keyword. You can't cast a Publication to a Keyword, so the cast fails and your keyword variable is assigned null.
Using dynamic casts in this way is an easy way to fool yourself. The "As" keyword (C# keyword not Tridion keyword) should be used when you don't know at compile time what type you expect. If you know that you expect an item of type Keyword, then you should write:
keyword = (Keyword)engine.GetObject(Constants.WEBDAV_UKEN_PUB);
This way - when the cast fails, you'll get an exception that identifies the problem correctly.
In TOM.NET we cannot get an object and specify which pub to read it from, we need to modify the TcmUri to be in context.
So:
Repository context = (Repository)session.GetObject(WEBDAV_UKEN_PUB);
TcmUri keywordInContext = new TcmUri(keyword.Id.ItemId, keyword.Id.ItemType, context.Id.ItemId);
Keyword keyword = (Keyword)session.GetObject(keywordInContext);

List Keys in JScript object using VBScript (Classic ASP)

I am using the JSON2 script in an asp page to parse JSON post data.
After parsing the data, I have an object in VBScript that allows for notations such as:
jsonData.key
I wish to parse through all the keys, however, I have no knowledge of the key names.
How would I go about doing this?
Example JSON:
{ "dbtable":"TABLE1", "dbcommand": "INSERT", "dbfilter": "ID" }
Thanks
You need to enumerate the property names of the object however this is a very alien thing to do in VBScript. You will need to build some other Jscript functions to assist converting the object into something more easily consumed in VBScript.
If the data is really as simplistic as the example in the question then you could use this function:-
function toDictionary(o)
{
var result = Server.CreateObject("Scripting.Dictionary");
for (var key in o)
result.Add(key, o[key]);
return result;
}
Now in VBScript:-
Dim myData: Set myData = toDictionary(jsonData);
For Each Key In myData
'' // Each Key is a property for jsonData
Next

Resources