|
There are 2 ways that you can achieve this.
1. Use a Ajax call to the other page and based on the result you get, you can update the current page. This is the easiest way.
2. Use a normal postback to the server, to the other page. While you do that, post the current URL as a parameter too. So in the other page, perform your logic, redirect to the passed URL and use session (recommended) or viewstate or some data store to send the values that you want to update the other page
Hope this helps and makes sense
Regards
|
|
|
|
|
window.open('http://www.site.com'); return false;
if you want to open a popup to another website
[EDIT]
you can't post data to another page in this manner.
Usually in this case, it's a credit card form, in which you get an api, and you populate your page with the textboxs, and then post to another page. The next page will consume the data, and send you back to the original page.
<Form id="whatever" and some attribute postback="nextpage.html" >
</form>
It's really not an asp.net issue, and just basic html, unless your using code behind to alter the form tag, or doing something fancy.
|
|
|
|
|
Does the
window.open('http://www.site.com'); return false;
only work in javascript? I am asking that question since I cannot get this to work in C#.
Can you also show me how to code the window open in a popup window?
Thans!
|
|
|
|
|
That's Javascript, doesnt' matter if it's c# or VB, Javascript runs on the client, and not the server.
dcof wrote: Can you also show me how to code the window open in a popup window?
Thans!
Your looking at it, in the last post and below, it open another browser instance or tab to the website you call.
window.open('http://www.site.com'); return false;
But you said you wanted to post data to another website, Javascript won't do that
It's the Form tag
http://www.w3schools.com/html/html_forms.asp[w3schools - Form Tag^]
[MSDN Form Tag^]
|
|
|
|
|
In a C# 2010 web form application, I would like to use a textbox object (or another object) that meets the following criteria:
1. The user can enter at least 8,000 or more characters,
2. The textbox wraps. In the same textbox area, the data wraps to the next line.
3. There are scrollbars that appear if needed. (this is optional)
The following is what I have so far but it only shows data on one line. i would like the data gto wrap to different lines:
<asp:TableRow ID="show"><asp:TableCell> asp:Label ID="LabelCauseText" runat="server" Text="Cause: " CssClass="whiteText" /> <asp:TextBox ID="TextBoxCause" runat="server" width="260" Wrap="true" MaxLength="25000" /> </asp:TableCell> </asp:TableRow>
Can you tell me what I can do to make the data wrap to more than one line?
|
|
|
|
|
Add TextMode="multiline" along with Rows="n" . Note that MaxLength does not work when the TextMode is set to multiline so you'll need to handle that separately.
<asp:TextBox ID="TextBoxCause" runat="server" width="260" TextMode="MultiLine" Rows="10" />
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
modified 9-Aug-12 18:40pm.
|
|
|
|
|
When I use the code you suggested, it worked fine. However there is a scrollbar that appears and the scrollbar does not work. Thus can you tell me how to make the scrollbar work?
|
|
|
|
|
Scrollbar starts working once the number of rows exceeds the Rows count.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
This is the first time that I am submitting a array of data to a web service, sort of in reverse.
So a web service can only accept primitive values, I get it. I want to pick up a json array of values, but not sure how to go about it.
So here's the layout.
JSON input
{
"template_Name": "tshirts",
"template_Array": [
{
"name": "Red",
"code": "RED"
},
{
"name": "Green",
"code": "GRN"
},
{
"name": "Blue",
"code": "BLU"
},
{
"name": "Black",
"code": "BLK"
},
{
"name": "White",
"code": "WHT"
}
]
}
And the Function declaration of the Web Service
<WebMethod()> _
Public Function create_DynamicCart_Template(
ByVal template_Name As String,
ByVal template_Array() As String) As String
Dim dwExitCode As Integer = 2
Dim json_response As StringBuilder = New StringBuilder
Dim html_Stream As String = Nothing
So because the template_Array() contains the array marker, it's not a primitive.
I read that I have to consume the web service in another application, or perhaps I just take out the array () chars, and swallow it as a char array.
Maybe make a class that represents the array, template_Array As TA,
Any suggestions?,
|
|
|
|
|
Well that was hard, especially finding info on it in vb, everything was c#, so I had to translate it. Wrote this at 1:30, but had to take a service call. Just got back to test it.
So a list of template_Elements, qualifies as a primitive, or it simply consumes the web method before processing, and passes on the json array for my manipulation.
If you've got insight into this, let me know, would like to learn more about it.
I'm going to try to parse the JSON back into an array, and write out some XML with it, hope it works, or I'm back to the drawing board.
<WebMethod()> _
Public Function create_DynamicCart_Template(
ByVal template_Name As String,
ByVal template_Array As List(Of templateElements)) As String
Dim dwExitCode As Integer = 2
Dim json_response As StringBuilder = New StringBuilder
Dim html_Stream As String = Nothing
Try
Dim jss As JavaScriptSerializer = New JavaScriptSerializer()
Dim elements = jss.Deserialize(Of List(Of templateElements))(template_Array.ToString)
Then the class
Public Class templateElements
Private privateName As String
Public Property Name() As String
Get
Return privateName
End Get
Set(ByVal value As String)
privateName = value
End Set
End Property
Private privateCode As String
Public Property Code() As String
Get
Return privateCode
End Get
Set(ByVal value As String)
privateCode = value
End Set
End Property
End Class
|
|
|
|
|
I dealt with this problem just yesterday. I found a really really convenient way to that. But I am horrible with VB.Net otherwise I could have helped you out. Do you think if I post the C# code, you would be able to figure the VB.Net version of it?
Btw, my methods only works with .Net Framework 3.0 and above. Is that what you use? If it's 4.0 I can give you a very easy method
|
|
|
|
|
Sure, I can translate with no problem
I did it working last night, I was surprised at what the fix was, and was able to generate my xml file.
Would like to see what you came up with, because I think I'm going to use more of this in the future, it's pretty cool.
|
|
|
|
|
Hey there,
Glad it worked out. Post your method here as well, so I can see whether I can improve my solution
ExpandoObject Documentation[^]
JSON Library[^] that I used
dynamic result = new ExpandoObject();
IDictionary<string, object> resultData = (IDictionary<string, object>)result;
resultData.add("templateName", "tshirts");
var templateArray = new [] {
new { Name = "Red", Code = "RED" },
new { Name = "Green", Code = "GRN" },
new { Name = "Blue", Code = "BLU" }
};
resultData.add("templateArray", templateArray);
string jsonString = JsonConvert.SerializeObject(result);
This will output a JSON string like the one you initially mentioned. I think the code is self explanatory. Feel free to reach out for further clarifications.
Hope this helps, cheers
|
|
|
|
|
Oh, that's pretty slick.
I built my json the old fashioned way using string builder.
I just caught the net4.0 comment, using 2.0 on this project.
I was just fine tuning my function to correct the first record error being sort of blank.
<WebMethod()> _
Public Function create_DynamicCart_Template(
ByVal template_Name As String,
ByVal template_Array() As templateElements) As String
Dim dwExitCode As Integer = 2 'An unknown error has occured
Dim json_response As StringBuilder = New StringBuilder
Try
Dim bTemplates As Boolean = DoesFoldersExist("~/App_Data/Products/dynamicItems/templates")
Dim bDisplay As Boolean = DoesFoldersExist("~/App_Data/Products/pageDisplay")
'Create the First Record
Dim new_Template As dynamicItem3.template = New dynamicItem3.template
Dim new_Element1 As dynamicItem3.templateElement_1 = New dynamicItem3.templateElement_1
new_Element1.Name = template_Array(0).Name
new_Element1.suffix = template_Array(0).Code
If (template_Array(0).Type.ToUpper = "SIMPLE") Then
new_Element1.elementType = dynamicItem3.templateElement_1ElementType.Simple
Else
new_Element1.elementType = dynamicItem3.templateElement_1ElementType.Complex
End If
Dim new_Element1_Record() As dynamicItem3.templateElement_1 = {new_Element1}
Dim new_Element1_Record_Count As Integer = 0
'Now Build the rest of the records
For i As Integer = 1 To template_Array.Length - 1
'Build the XML Array from the JSON Array
Array.Resize(new_Element1_Record, new_Element1_Record.Length + 1)
new_Element1_Record(new_Element1_Record.Length - 1) = New dynamicItem3.templateElement_1
new_Element1_Record(new_Element1_Record.Length - 1).Name = template_Array(i).Name
new_Element1_Record(new_Element1_Record.Length - 1).suffix = template_Array(i).Code
If (template_Array(i).Type.ToUpper = "SIMPLE") Then
new_Element1_Record(new_Element1_Record.Length - 1).elementType = dynamicItem3.templateElement_1ElementType.Simple
Else
new_Element1_Record(new_Element1_Record.Length - 1).elementType = dynamicItem3.templateElement_1ElementType.Complex
End If
new_Element1_Record_Count += 1
Next i
'Package the Array into Pure Sweet XML, and write it to the Disk Drive
Dim DataLocation As String = Nothing
DataLocation = HttpContext.Current.Server.MapPath("~/App_Data/Products/dynamicItems/templates/" & template_Name & ".xml")
Dim XmlResponse As New dynamicItem3.template
XmlResponse.Version = "1.0"
XmlResponse.CreationDate = DateTime.Now.ToString("yyyy-MM-dd")
XmlResponse.templateName = template_Name
XmlResponse.element_1 = new_Element1_Record
'Now Lets Write out the file as a MemoryStream
Dim serializer As XmlSerializer
serializer = New XmlSerializer(GetType(dynamicItem3.template))
'Now we have to write out a file for certification
Dim response_serializer As XmlSerializer = Nothing
response_serializer = New XmlSerializer(GetType(dynamicItem3.template))
Dim Writer As StreamWriter = Nothing
Writer = New StreamWriter(DataLocation)
response_serializer.Serialize(Writer, XmlResponse)
Writer.Close()
Writer = Nothing
response_serializer = Nothing
serializer = Nothing
XmlResponse = Nothing
dwExitCode = 0
Catch ex As Exception
'An error occured building the XML - Send 1
dwExitCode = 1
End Try
With json_response
.Append("{")
.Append(" ""template_ExitCode"" : " & dwExitCode.ToString & " ")
.Append("}")
End With
Dim js_response As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer
js_response.Serialize(json_response.ToString)
js_response = Nothing
Return json_response.ToString
End Function
|
|
|
|
|
Woahh.. That's one long solution I think you can simplify that solution by compiling the logic into one class using a dictionary object or a stringbuilder object internally to hold the data.
I will post a sample, if I get time around one of these days.
|
|
|
|
|
I thought it was pretty optimized, considering it building a XML file, and writing it to disk.
|
|
|
|
|
Hey there,
I am sorry about the really late reply. But I've been working with web technologies and XML manipulation much. One thing I've learnt is that XML is great for data transferring but it's slow and heavy.
For instance, if you want to send one piece of data that is huge XML is fine. But if you want to send lots of small pieces of data, the number of tags generated for each small object, adds an unnecessary weight. I hope this gives you the basic idea of what I mean.
I won't have time to write a fully generalized JSON class But it should be really easy to write a logic to generalize your specific class without using XML. Let me know if you still want it.
Basic idea for it would be to implement an interface on all the classes you want to JSONify (I made that word up :P) and pass it on to a special class. The implementation of the interface would return a JSON data string for that specific object. The special class would bind them all to one piece of data.
Hope this helps, Regards
|
|
|
|
|
That's OK on the late reply, it's a discussion, and I got it working using a class with get and set to accept a JSON array of items. So I understand how to pass non-primitives to a web service now.
I find XML to be really fast. I use XML reader and writer, and a class file to code against. So basically each xml element is like an array, that can be resized with Array.resize.
And yes it does help solidify the techniques needed to accomplish the task.
Thanks for collaborating with me on the subject. Guess not that many people are at that level yet.
|
|
|
|
|
hehe It's my pleasure to have a good discussion and help someone out.
XML is not slow for your eye, but it's really slow when it comes to traversing the nodes (i.e. compared to others of course). Anyways, am sure for your purpose it won't effect much. However I'll try to write a sample code that would perform json serialization easily, over the weekend, and share it.
regards
|
|
|
|
|
It's a holiday weekend here, labor day, but I may send another array to a web service next week. I'm reworking my shopping cart and checkout program, implementing better and faster code, while cleaning up.
Have a great weekend!
|
|
|
|
|
I am using Page.Response.Redirect and the following code is not working:
Page.Response.Redirect("test.aspx")
I never get to the requested page.
I have tried
Page.Response.Redirect("test.aspx", false )
and that does not work.
The code that calls the routine is the following:
onKeyPress="return numbersonly(this, event)"
The user has to enter a value in the textbox for the code to work.
Do you think I need to setup the absolute path in this call?
Thus do you think I need another event to trigger the call to the correct method call?
What would you suggest?
|
|
|
|
|
Correct me if I'm wrong on this
Objects like Request, Response, Server are part of the HttpContext, which I think is a link to the web server, and allows the web server to communicate with asp.net
So when you get more advanced with your code, and you no longer bind objects, then you use
httpContext.current.response.redirect("~/default.aspx")
As far as the folder system goes
If I have a folder structure like
/
/images/
/admin/management/login.aspx
/admin/management/logout.aspx
I'm in the root, and want the image folder
redirect(~/images/default.aspx")
I'm in /admin/management/ and I want the logout page
redirect("logout.aspx")
now I want the root default
redirect("~/")
Using Page is for talking to Page Objects, like the header tag, script tags, register a script via the client script manager
Hope that helps
|
|
|
|
|
dcof wrote: The code that calls the routine is the following
Page.Response.Redirect is a server-side function, yet return numbersonly(this, event) appears to be a call to a JavaScript function. That's not going to work. Here is an example of how you can do a server-side redirect:
<%@ Page Language="vb" AutoEventWireup="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub btnTest_Click(sender As Object, e As System.EventArgs)
Page.Response.Redirect("http://www.google.com/")
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test Redirect</title>
</head>
<body>
<form id="frmMain" runat="server">
<asp:Button runat="server" ID="btnTest" Text="Redirect" onclick="btnTest_Click" />
</form>
</body>
</html>
If you want to do it with JavaScript, it would be different (you'd use window.location ).
|
|
|
|
|
|
Can you show me how you use
"window,location("/index.aspx");"
in javascript?
how would you wire up this feature to the web form page?
|
|
|
|
|