Showing posts with label page. Show all posts
Showing posts with label page. Show all posts

Saturday, March 31, 2012

Submitting Data to Another Page Using ASP.NET

I need to post an ASP.NET form between sites for report processing.
Site A contains the asp.net forms and site B contains Java Servlets for
report processing.

All form fields values must be passed to the reporting servlet via http
post method. No parameters can be transmitted by URL. The report must
display in a NEW browser window. Does anyone know how to set a target
using httpwebrequest or is there another alternative?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Hi Dennis,

I've had success doing that using the Webclient class. You need to know
exactly what form field names the target expects.

Not sure about setting it to open in a new page.

Anyway, here's some code to give you an idea:

Sub DoPost()
Dim uriString As String = _
"http://localhost/p4320work/mySpecialPage.aspx"
Dim strGoName As String
strGoName = TextBox1.Text
' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebClient
Dim myNameValueCollection As New _
System.Collections.Specialized.NameValueCollection
myNameValueCollection.Add("go1", strGoName)
myNameValueCollection.Add("Button1", "")
Dim responseArray As Byte() = myWebClient.UploadValues _
(uriString, "POST", myNameValueCollection)
' Response.Redirect("http://msdn.microsoft.com/")
End Sub

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Call DoPost()
End Sub

<form id="Form1" method="post" runat="server">
<P>
<asp:TextBox id="TextBox1" runat="server">test</asp:TextBox></P>
<P>
<asp:Label id="Label1" runat="server">Label</asp:Label></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
</form
Ken
Microsoft MVP [ASP.NET]
Toronto

<Dennis E. Jones>; "Jr." <djone2@.jcpenney.com> wrote in message
news:e1jFoNTCFHA.520@.TK2MSFTNGP09.phx.gbl...
>I need to post an ASP.NET form between sites for report processing.
> Site A contains the asp.net forms and site B contains Java Servlets for
> report processing.
> All form fields values must be passed to the reporting servlet via http
> post method. No parameters can be transmitted by URL. The report must
> display in a NEW browser window. Does anyone know how to set a target
> using httpwebrequest or is there another alternative?
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Yes, that works...but I still need a solution for the target attribute.
Thanks for your help.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
If all you want is a submit button that opens your servlet in a new
window, .NET never comes into play:

<form action="yourServlet.jsp" target="_blank" method="post">
<input type=...>
<input type="submit">
</form
Retarget your form from the HTML side.
Jason
http://www.expatsoftware.com
If I do not use .NET, then my server controls also go away....I guess a
javascript injected into the page on postback would work, but only for
those browsers that support Javascript.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Submitting Data to Another Page Using ASP.NET

I need to post an ASP.NET form between sites for report processing.
Site A contains the asp.net forms and site B contains Java Servlets for
report processing.
All form fields values must be passed to the reporting servlet via http
post method. No parameters can be transmitted by URL. The report must
display in a NEW browser window. Does anyone know how to set a target
using httpwebrequest or is there another alternative?
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!Hi Dennis,
I've had success doing that using the Webclient class. You need to know
exactly what form field names the target expects.
Not sure about setting it to open in a new page.
Anyway, here's some code to give you an idea:
Sub DoPost()
Dim uriString As String = _
"http://localhost/p4320work/mySpecialPage.aspx"
Dim strGoName As String
strGoName = TextBox1.Text
' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebClient
Dim myNameValueCollection As New _
System.Collections.Specialized.NameValueCollection
myNameValueCollection.Add("go1", strGoName)
myNameValueCollection.Add("Button1", "")
Dim responseArray As Byte() = myWebClient.UploadValues _
(uriString, "POST", myNameValueCollection)
' Response.Redirect("http://msdn.microsoft.com/")
End Sub
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Call DoPost()
End Sub
<form id="Form1" method="post" runat="server">
<P>
<asp:TextBox id="TextBox1" runat="server">test</asp:TextBox></P>
<P>
<asp:Label id="Label1" runat="server">Label</asp:Label></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
</form>
Ken
Microsoft MVP [ASP.NET]
Toronto
<Dennis E. Jones>; "Jr." <djone2@.jcpenney.com> wrote in message
news:e1jFoNTCFHA.520@.TK2MSFTNGP09.phx.gbl...
>I need to post an ASP.NET form between sites for report processing.
> Site A contains the asp.net forms and site B contains Java Servlets for
> report processing.
> All form fields values must be passed to the reporting servlet via http
> post method. No parameters can be transmitted by URL. The report must
> display in a NEW browser window. Does anyone know how to set a target
> using httpwebrequest or is there another alternative?
>
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!
Yes, that works...but I still need a solution for the target attribute.
Thanks for your help.
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
If I do not use .NET, then my server controls also go away....I guess a
javascript injected into the page on postback would work, but only for
those browsers that support Javascript.
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!

Submitting Form to Database

I have an ASP.Net page created with a table I made to look like a form
for our benefit request program. How do I code this properly to send
it to a table in our database.

For the sake of me learning how to do this lets just do short example
like. I have an aspx page with a label for name and a text box where
a user can input their name.

I have a database table called tblName with a column called name where
the submitted names go.

How do I code it so the name is submitted, a confirmation page is
shown and the data goes to the database when I click submit? Any help
is greatly appreciated.

Thanks,
BenIf you look at the ASP.NET QUICKSTART tutorials on the asp.net website, it
has lots of examples like this. QUICKSTARTS also installs as an option with
Visual Studio.
--
--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com
"Ben" wrote:

Quote:

Originally Posted by

I have an ASP.Net page created with a table I made to look like a form
for our benefit request program. How do I code this properly to send
it to a table in our database.
>
For the sake of me learning how to do this lets just do short example
like. I have an aspx page with a label for name and a text box where
a user can input their name.
>
I have a database table called tblName with a column called name where
the submitted names go.
>
How do I code it so the name is submitted, a confirmation page is
shown and the data goes to the database when I click submit? Any help
is greatly appreciated.
>
Thanks,
Ben
>

Submitting Form to Database

I have an ASP.Net page created with a table I made to look like a form
for our benefit request program. How do I code this properly to send
it to a table in our database.
For the sake of me learning how to do this lets just do short example
like. I have an aspx page with a label for name and a text box where
a user can input their name.
I have a database table called tblName with a column called name where
the submitted names go.
How do I code it so the name is submitted, a confirmation page is
shown and the data goes to the database when I click submit? Any help
is greatly appreciated.
Thanks,
BenIf you look at the ASP.NET QUICKSTART tutorials on the asp.net website, it
has lots of examples like this. QUICKSTARTS also installs as an option with
Visual Studio.
--
--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com
"Ben" wrote:

> I have an ASP.Net page created with a table I made to look like a form
> for our benefit request program. How do I code this properly to send
> it to a table in our database.
> For the sake of me learning how to do this lets just do short example
> like. I have an aspx page with a label for name and a text box where
> a user can input their name.
> I have a database table called tblName with a column called name where
> the submitted names go.
> How do I code it so the name is submitted, a confirmation page is
> shown and the data goes to the database when I click submit? Any help
> is greatly appreciated.
> Thanks,
> Ben
>

Submitting IFrame in asp.net

hi
I have this situation where I need to do some server side execution
without posting the page.
I used to do this in asp using IFrame, but it's not working in asp.net.
I had a form and iframe element in the web page as follow:
<form id=MainForm ...>
this is the form that the user see
</form>
<form id= myForm method=post action="form.aspx" target="myHiddenFrame">
<input type=hidden id=hiddenField>
</form>
<iframe id="myHiddenFrame" src=PortfolioName.aspx name="myHiddenFrame"
style="width:0px; height:0px; border: 0px"></iframe>
then I had a javascript function: window.myForm.submit();
It seems that i can't put target="myHiddenFrame", the target can only be
_self, _parent...
How can I submit in an IFrame element ?
regards
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!iframe is working in asp.net in the regular way. It just has to sit inside a
form. And there can be only one form in a page. And there should be
runat=server set for the form tag.
Eliyahu
"Naim" <anonymous@.devdex.com> wrote in message
news:%23YXooBz7EHA.3592@.TK2MSFTNGP09.phx.gbl...
> hi
> I have this situation where I need to do some server side execution
> without posting the page.
> I used to do this in asp using IFrame, but it's not working in asp.net.
> I had a form and iframe element in the web page as follow:
> <form id=MainForm ...>
> this is the form that the user see
> </form>
> <form id= myForm method=post action="form.aspx" target="myHiddenFrame">
> <input type=hidden id=hiddenField>
> </form>
> <iframe id="myHiddenFrame" src=PortfolioName.aspx name="myHiddenFrame"
> style="width:0px; height:0px; border: 0px"></iframe>
> then I had a javascript function: window.myForm.submit();
> It seems that i can't put target="myHiddenFrame", the target can only be
> _self, _parent...
> How can I submit in an IFrame element ?
> regards
>
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!

Submitting IFrame in asp.net

hi

I have this situation where I need to do some server side execution
without posting the page.
I used to do this in asp using IFrame, but it's not working in asp.net.

I had a form and iframe element in the web page as follow:
<form id=MainForm ...>
this is the form that the user see
</form>
<form id= myForm method=post action="form.aspx" target="myHiddenFrame">
<input type=hidden id=hiddenField>
</form
<iframe id="myHiddenFrame" src=PortfolioName.aspx name="myHiddenFrame"
style="width:0px; height:0px; border: 0px"></iframe
then I had a javascript function: window.myForm.submit();

It seems that i can't put target="myHiddenFrame", the target can only be
_self, _parent...

How can I submit in an IFrame element ?

regards

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!iframe is working in asp.net in the regular way. It just has to sit inside a
form. And there can be only one form in a page. And there should be
runat=server set for the form tag.

Eliyahu

"Naim" <anonymous@.devdex.com> wrote in message
news:%23YXooBz7EHA.3592@.TK2MSFTNGP09.phx.gbl...
> hi
> I have this situation where I need to do some server side execution
> without posting the page.
> I used to do this in asp using IFrame, but it's not working in asp.net.
> I had a form and iframe element in the web page as follow:
> <form id=MainForm ...>
> this is the form that the user see
> </form>
> <form id= myForm method=post action="form.aspx" target="myHiddenFrame">
> <input type=hidden id=hiddenField>
> </form>
> <iframe id="myHiddenFrame" src=PortfolioName.aspx name="myHiddenFrame"
> style="width:0px; height:0px; border: 0px"></iframe>
> then I had a javascript function: window.myForm.submit();
> It seems that i can't put target="myHiddenFrame", the target can only be
> _self, _parent...
> How can I submit in an IFrame element ?
> regards
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Submitting HTML page data through form.

Hi,

Iam trying to submit data using form.
I have taken Text area in the form.
I want to submit Html page data(data is something like <Html> <body> hello</body></html>)
through this form.

But it is giving error. How to handle this situation

Server Error in '/webs' Application.
------------------------

A potentially dangerous Request.Form value was detected from the client (ta=" <html><head></head><...").Please read the following:
Request Validation - Preventing Script Attacks

It will show you how you can effectively "turn off" this error. However, youmust take notice of the warnings in red text. Do not just turn off the error, without validating the input yourself.
Hi,

.NET 1.1 has built in protection against script injections through textbox, textareas etc., However, if you are sure that your users won't do the hacking, you can remove this checking functionality by adding the ValidateRequest="false" to the @.Page directive of your aspx page.

If you want this for whole of your application, you can specify the same in the web.config

Hope it helps.
Hello
Thanks for help.

It is working fine.

But While printing the result it is printing like
<html><head></head><body>hello</body></html>
How to handle this situation.
Hi there,

You will have to decode the information before actually bind to a control.

for e.g

Text1.text = Server.htmldecode(dr("myHtml).tostring)

HTH
Thanks to all .
It is running fine.

Submitting the form correctly using the enter key

Hi all,

Simple problem:

I have a simple form and a submit and cancel image button underneath.

I also have a logout image button at the top of the page. This button is
rendered from a user control that is seperate from the form page itself.

At the moment if I press enter when inside a textbox the log out button is
activated. How can I make sure that the submit button is activated when the
user presses enter?

Many thanks all

Kind RegardsEnter activates the first submit button in the layout. See details at
http://www.allasp.net/enterkey.aspx

Can you place the logout button after the submit one?

Eliyahu

"thechaosengine" <sh856531@.microsofts_free_email_service.com> wrote in
message news:O5N%23amv9EHA.2996@.TK2MSFTNGP10.phx.gbl...
> Hi all,
> Simple problem:
> I have a simple form and a submit and cancel image button underneath.
> I also have a logout image button at the top of the page. This button is
> rendered from a user control that is seperate from the form page itself.
> At the moment if I press enter when inside a textbox the log out button is
> activated. How can I make sure that the submit button is activated when
the
> user presses enter?
> Many thanks all
> Kind Regards
thechaosengine wrote:
> Hi all,
> Simple problem:
> I have a simple form and a submit and cancel image button underneath.
> I also have a logout image button at the top of the page. This button
> is rendered from a user control that is seperate from the form page
> itself.
> At the moment if I press enter when inside a textbox the log out
> button is activated. How can I make sure that the submit button is
> activated when the user presses enter?
> Many thanks all
> Kind Regards

You can capture the Enter key with JavaScript
to get the behavior you want:
http://dotnetjunkies.com/WebLog/dar...03/03/8374.aspx

--

Riki

Submitting the form correctly using the enter key

Hi all,
Simple problem:
I have a simple form and a submit and cancel image button underneath.
I also have a logout image button at the top of the page. This button is
rendered from a user control that is seperate from the form page itself.
At the moment if I press enter when inside a textbox the log out button is
activated. How can I make sure that the submit button is activated when the
user presses enter?
Many thanks all
Kind RegardsEnter activates the first submit button in the layout. See details at
http://www.allasp.net/enterkey.aspx
Can you place the logout button after the submit one?
Eliyahu
"thechaosengine" <sh856531@.microsofts_free_email_service.com> wrote in
message news:O5N%23amv9EHA.2996@.TK2MSFTNGP10.phx.gbl...
> Hi all,
> Simple problem:
> I have a simple form and a submit and cancel image button underneath.
> I also have a logout image button at the top of the page. This button is
> rendered from a user control that is seperate from the form page itself.
> At the moment if I press enter when inside a textbox the log out button is
> activated. How can I make sure that the submit button is activated when
the
> user presses enter?
> Many thanks all
> Kind Regards
>
thechaosengine wrote:
> Hi all,
> Simple problem:
> I have a simple form and a submit and cancel image button underneath.
> I also have a logout image button at the top of the page. This button
> is rendered from a user control that is seperate from the form page
> itself.
> At the moment if I press enter when inside a textbox the log out
> button is activated. How can I make sure that the submit button is
> activated when the user presses enter?
> Many thanks all
> Kind Regards
You can capture the Enter key with JavaScript
to get the behavior you want:
http://dotnetjunkies.com/WebLog/dar...03/03/8374.aspx
Riki

subroutines or functions wont work.

any time i try coding a function or a subrouting the page won't run. iget error msg: BC30289: Statement cannot appear within a method body. End of method assumed.

here's my code. PLEASE HELP!, what am i typing wrong??
<%@dotnet.itags.org. Page Language="VB" %>
<script runat="server"
' Insert page code here
'

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<%
Dim arrPrimeNos, arrNames
Sub subPrintArray(arrToPrint, iStartValue, iStopValue)
Dim iCounter
For iCounter = iStartValue to iStopValue
Response.Write(arrToPrint(iCounter))
Response.Write("<BR>")
Next
End Sub
arrPrimeNos=Array(2,3,5)
arrName=Array("John","Mary","Bolek")

'call subroutine
subPrintArray arrNames, 2, 3
%
</form>
</body>
</html>1. You'd better put the server side code in <script> tag if you use inline coding. Using <% %> is not a .net way.

2. You can only call a method (function, subrouting or event handler) from a method (function, subrouting or event handler), so your code need to change like this:


<%@. Page Language="VB" %>
<script runat="server"
Sub page_load

Dim arrPrimeNos() As Integer = {2, 3, 5}
Dim arrNames() As String = {"John", "Mary", "Bolek"}

'call subroutine
subPrintArray arrNames, 2, 3
End Sub

Sub subPrintArray(arrToPrint, iStartValue, iStopValue)
Dim iCounter
For iCounter = iStartValue to iStopValue
Response.Write(arrToPrint(iCounter))
Response.Write("<BR>")
Next
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
</form>
</body>
</html>


thank you very much

Subscript out of range

I have an asp page which connects to a SQL database, and requires login. If I attempt to the load the page in IE, I get absolutely nothing (just a blank white page with no error messages at all). If I attempt to load it in Firefox or Opera, I get the following error message:

Microsoft VBScript runtime error '800a0009'
Subscript out of range: '[number: 0]'
/KnowledgeBase/sos-kb.inc.asp, line 82

And here are the lines of code in question:

Line 80 Dim CurrentDomain, AuthInfo
Line 81 AuthInfo = Split(Request.ServerVariables("LOGON_USER"), "\", -1, 1)
Line 82 CurrentDomain = AuthInfo(0)

The site was working absolutely fine and for some reason, one day, it just stopped loading.

Any help would be appreciated.Uhm... when you load it in IE, view source. Do you see anything?

What have you recently changed?

Subst Question

Anyone have insight as to why an ASP.NET app (1.1) would not recognize a substituted drive on the first page hit? I have done a subst e: c:\ for my local development (to mirror production), but every time that I hit the asp.net app (and force compilation maybe?) I get can't find portion of path e:\ error. (for logging components I have reference to e:\myfolder\logs in my web.config file.) If I hit my browser's back button and try again it works. Thanks in advance!

Not sure about your specific problem, but why not use Server.MapPath() to map relative paths to absolute? That way it will work on any server.
Sorry, I didn't have email enabled, so I'm just getting back to checking on this... Thanks for the comment. I'm not sure this applies, unless I'm not up-to-speed on Server.MapPath(). Isn't that just for relative path to physical path mappings? We use this regularly for web site content mapping. However, we have logging components that specify a non-web location on disk (the e: drive) for the log file location. The web site, itself, may be anywhere, just mapped with a virtual dir. Anyone else have any ideas on what's happening with ASP.NET?

Wednesday, March 28, 2012

Substring

In an aspx (asp2.0) page in C# I have a string array. The array contains
letters separated into two groups by a dash (-). I want to obtain the
letters before the dash. I use the following code. Strangely, when the
array has a value of "MOD-AS" Label3 displays "3" while Label4 displays -1.
What's going on ? What is changing the value of variable mn ? Thanks,
Jim
int i = 32;
string s1;
string s2;
s1 = Ante_Arr[i];
int mn = s1.IndexOf("-");
Label3.Text = mn.ToString(); // the displayed value is 3
try
{
s2 = s1.Substring(1, mn); // throws an error: length can not be less
than zero
}
catch
{
Label4.Text = mn.ToString(); // the displayed value is -1
}Maybe it's scope?
Put the int mn = s1.IndexOf("-"); line into the try block, or take a look at
the value of mn before the s2 = s1.Substring(1, mn); line.
"Jim McGivney" <mcgiv1@.no-spam.sbcglobal.net> wrote in message
news:O7EM879dGHA.3348@.TK2MSFTNGP03.phx.gbl...
> In an aspx (asp2.0) page in C# I have a string array. The array contains
> letters separated into two groups by a dash (-). I want to obtain the
> letters before the dash. I use the following code. Strangely, when the
> array has a value of "MOD-AS" Label3 displays "3" while Label4
> displays -1.
> What's going on ? What is changing the value of variable mn ? Thanks,
> Jim
> int i = 32;
> string s1;
> string s2;
> s1 = Ante_Arr[i];
> int mn = s1.IndexOf("-");
> Label3.Text = mn.ToString(); // the displayed value is 3
> try
> {
> s2 = s1.Substring(1, mn); // throws an error: length can not be less
> than zero
> }
> catch
> {
> Label4.Text = mn.ToString(); // the displayed value is -1
> }
>

Substring

In an aspx (asp2.0) page in C# I have a string array. The array contains
letters separated into two groups by a dash (-). I want to obtain the
letters before the dash. I use the following code. Strangely, when the
array has a value of "MOD-AS" Label3 displays "3" while Label4 displays -1.
What's going on ? What is changing the value of variable mn ? Thanks,
Jim

int i = 32;
string s1;
string s2;
s1 = Ante_Arr[i];
int mn = s1.IndexOf("-");
Label3.Text = mn.ToString(); // the displayed value is 3
try
{
s2 = s1.Substring(1, mn); // throws an error: length can not be less
than zero
}
catch
{
Label4.Text = mn.ToString(); // the displayed value is -1
}Maybe it's scope?

Put the int mn = s1.IndexOf("-"); line into the try block, or take a look at
the value of mn before the s2 = s1.Substring(1, mn); line.

"Jim McGivney" <mcgiv1@.no-spam.sbcglobal.net> wrote in message
news:O7EM879dGHA.3348@.TK2MSFTNGP03.phx.gbl...
> In an aspx (asp2.0) page in C# I have a string array. The array contains
> letters separated into two groups by a dash (-). I want to obtain the
> letters before the dash. I use the following code. Strangely, when the
> array has a value of "MOD-AS" Label3 displays "3" while Label4
> displays -1.
> What's going on ? What is changing the value of variable mn ? Thanks,
> Jim
> int i = 32;
> string s1;
> string s2;
> s1 = Ante_Arr[i];
> int mn = s1.IndexOf("-");
> Label3.Text = mn.ToString(); // the displayed value is 3
> try
> {
> s2 = s1.Substring(1, mn); // throws an error: length can not be less
> than zero
> }
> catch
> {
> Label4.Text = mn.ToString(); // the displayed value is -1
> }

Success Page or Feedback on Insert or Update

How do I make it so that when someone inserts a new record or updates a current record that it either takes them to a success page or shows feedback right in the page they are in. Right now when I do an update or insert, it goes into the database, but there is no feedback on the page indicating success or failure.

Hey,

Well, you could setup a multiview, which then you switch to the other multiview page, bind the single insert result, and let them know of the status; if there is an error with the result, you may want to stay in the current view and display the problem with an error message, allowing them to re-edit their information. But, it depends how you want to set it up. Do you want to see the initial result and have the information there, or do you want a separate confirmation page?

Ultimately, that is up to your design; it can be done however you prefer.


I am really new to ASP.NET 2. I have several forms throughout my site now, but none of them give feedback on insert or update. I am not sure what multiview is though. Can you direct me to a good tutorial on this? I appreciate the prompt response.

I would just be happy to even just have it say success under the insert or update button at this point.


Okay, I found the Multiview and read up on it a little. Never notived that button before. Big Smile

So, now I have this code:

 <asp:MultiView ID="MultiView1" runat="server"> <asp:View ID="View1" runat="server"> An error occured while submitting your form</asp:View> <asp:View ID="View2" runat="server"> You have successfully submitted your information</asp:View> </asp:MultiView>

I have a formview called FormView1 with an Insert Button. So, I have to tell it when it inserts correctly to show view two and when there is an error to show view 1 right?

Do I need to do something to the insert button or to the formview to make this happen?


Okay, I am reading now about this:

ItemInsertedOnItemInsertedFormViewInsertedEventArgs

Am I on the right track?


Hey,

Yes, though if that is all you are showing, you could also use a label for that instead, if that is easier for you. Basically override the FormView's ItemInserted/ItemDeleted, which has an e.Exception property, and if this object exists, an error occurred. Make sure to set e.ExceptionHandled to true with your approach. You'll also want to log it maybe, in case the problem isn't with the data, but with something else.


Whatever solution you decide to go with, please be sure to confirm that a page refresh does not cause a duplicate record to be inserted. Me personally, I have 1 confirmation page for my project and I perform a redirect on completion. The confirmation page uses session variables I set on the previous page to dictate how the confirmation page should appear. Seems to work well for me.


How do you do direct to the page once the form is submitted?

Okay, so I found this microsoft article and I think this is what I am trying to do:

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.formviewinsertedeventargs.aspx

So, I have the insert form with a label named MessageLabel.

In my aspx.vb file I have the following code:

Sub FormView1_ItemInserted(ByVal senderAs Object,ByVal eAs FormViewInsertedEventArgs)If e.ExceptionIs Nothing Then If e.AffectedRows = 1Then MessageLabel.Text ="Record Inserted Successfully"Else MessageLabel.Text ="An error occured during the insert operation"End If Else MessageLabel.Text = e.Exception.Message e.ExceptionHandled =True e.KeepInInsertMode =True End If End Sub

I think this is what I need, but in my editor the MessageLabel.Text part is underlined and shows Name "MessageLabel" is not declared.

Can I get a little more help on this? Does it look like this is what I need to do?


Okay, I had to move the MessageLabel outside of my formview to get this working. I also had to add the following line to my FormView Tag:

OnItemInserted="FormView1_ItemInserted"

Hey,

Yes, but if MessageLabel isn't declared, what it's saying is there isn't a:

<asp:Label id="MessageLabel" runat="server"></asp:Label>

On the form. Is that incorrect?


Well, I had the MessageLabel in my insert view on the Form. When I had it like that, it showed that it was undeclared. Then after I moved it up above the formview then I wasn't getting that anymore.

Is there a way to make the whole page refresh though once it is inserted? I have a gridview at the top that shows the request and I don't want them to refresh the page to see the results because it might double post the insert form at the bottom of the page.


Hey,

MessageLabel in the formview is part of the formview; it's not its own control. Yes, that is why you got that. They shouldn't have to refresh. On FormView_ItemInserted, the gridview should be rebound by calling DataBind(). See my blog (http://dotnetslackers.com/community/blogs/bmains/default.aspx) as I wrote about that recently.

Sudden Cookie problem is .aspx page


Cookie problem in .aspx application.

I have a cookie problem that makes no sense. I get this error when the page
loads:

Object reference not set to an instance of an object.

I am reading the cookie into a var with standard code.

Where the problem makes no sense is that this application sits on my
network, and all
other machines load the page fine. As has the page loaded on all machines
fine since the application
has been in development. Only now, there seems to be a problem.

The other machines are running XP Pro and Windows 2000 Pro, respectfully.
The machine that throws the error is running XP.

All machines have been updated regularly.

Does any know what in the world could be happening with the XP machine for
it never loads the cookie when the page is requested? (note, no privacy
changes have been made to the browser on the XP machine and the machine is
virus free)

Any help would be greatly appreciated.

Branton EllerbeePost your code please

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"branton ellerbee" <blrb@.sbcglobal.net> wrote in message
news:3olOb.6716$kg1.1173@.newssvr24.news.prodigy.co m...
>
> Cookie problem in .aspx application.
> I have a cookie problem that makes no sense. I get this error when the
page
> loads:
> Object reference not set to an instance of an object.
> I am reading the cookie into a var with standard code.
> Where the problem makes no sense is that this application sits on my
> network, and all
> other machines load the page fine. As has the page loaded on all machines
> fine since the application
> has been in development. Only now, there seems to be a problem.
> The other machines are running XP Pro and Windows 2000 Pro, respectfully.
> The machine that throws the error is running XP.
> All machines have been updated regularly.
> Does any know what in the world could be happening with the XP machine for
> it never loads the cookie when the page is requested? (note, no privacy
> changes have been made to the browser on the XP machine and the machine is
> virus free)
> Any help would be greatly appreciated.
> Branton Ellerbee

Suddenly being prompted for username and password on new site?

I have a small site that I launched a week ago. All static pages other than one page that emails user inquiries to me. I just had the default permissions and no extra authentication setup, no logins, etc. I changed one word on one page this morning, published the site to our webserver through VS2003, everything worked fine. I modified one other page, basically commenting out a <DIV> tag, published the site. Now it prompts me for a username and password for every page. If I keep hitting the cancel button, the page will eventually display, sometimes only partially (some graphics might be missing, the header and/or sidebar image are missing on some pages), but the page displays with at least most of the info.

I didn't touch the directory/file or IIS configuration, didn't edit the web.config file, etc. I tried un-commenting the DIV tag, but nothing changes. It works fine on the http://localhost web server on my development machine through VS.

What permissions should the default anonymous website visitor have in the website directory/sub-dirs/files?

What can I do to fix this, it's on our live site. Thanks.

After thinking about it and the way the graphics weren't all showing, I dug some more and discovered that when I clicked on my /Images directory, I got an 'access is denied' dialog on the server. I rebooted the web server and then the /Images directory didn't show up at all, so I re-published the website from VS and it works now. Freaky...

Monday, March 26, 2012

Suddenly my web run very slow.

I have very big and complicated website. Suddenly (in the past few days) it started to run very slow. In each page it "can't find" one or two images (usually very small ones like arrow or something) and the browser show "open 1 item…" and stuck. As much as I can remember I didn't change any thing that related to the images or to my home page.

Does any body have idea what can cause such behavior?

Have you rebooted recently? You might have some memory issues on the server.

Nick


oh, yes... again and again.

Suggested means to cope with commas etc.

G'day,
In a typical 'contact us' type page what is a recommended way to ensure a message text box gets dealt with properly rather than break at comma's etc.

Is it as simple as using server.encodeHTML() on every passed variable? When I do this I still seem to have problems.

GeoffWhy would you break at commas? I don't get the problem.
Sorry. Error was happening when writing a record of the email to a database.

So if I can change my question...

Is there a best-practice' approach to handling commas etc. when writing to database eg:..."insert into myTable message = '" & server.encodeHTML(msg.text) & "'" is the sort of thing that was breaking if a comma existed in the textbox called msg?

Thanks,

Geoff
The commas should not mess it up within the quotes.

If an apostrophe appears within the string ('), then it will close the string and this is what will mess it up.

The best practice is to use Parameters. These will take care of all these issues as well as protect you against SQL injection and a few other problems you may not have noticed yet.

Suggestion for App

I am trying to do a web page with a network status on it for several apps. I have tried it one way and posted it here but no replies. Any suggestions on how to have it ping a server with many different servers with online if it gets a reply or offline if it gets the time out or cant ping. Any helpe would be appreciated.

Thanks

To simply ping a server it is as simple asMy.Computer.Network.Ping("hostnameOrIp")

It will return true or false.


Cool. What I am trying to do is take that information and put in a page that says Online or Offline. But I have several Servers to do this. Any suggestions? Thanks for replying by the way.

Well, do one ping per server :P The way ping works is that it tries to send small packets to the destinated IP, if the data gets through we have PING! (funny word btw ;-). Things will get a bit different if you want to check if the server answers on specific ports. But just to do ping on several servers is piece of cake:

If My.Computer.Network.Ping("server1") = true
response.write("Online")
else
response.write("Offline")
end if

If My.Computer.Network.Ping("server2") = true
response.write("Online")
else
response.write("Offline")
end if


I would setup an ArrayList to hold all the servers, then loop through them, ping, and print their status:

Dim arrServersAs New ArrayList()Dim intCountAs IntegerDim strMessageAs StringarrServers.Add("192.168.1.100")arrServers.Add("192.168.1.101")arrServers.Add("192.168.1.102")For intCount = 0To arrServers.Count - 1 strMessage ="Server " &CStr(arrServers(intCount))If My.Computer.Network.Ping(arrServers(intCount))Then strMessage +=" is online"Else strMessage +=" is offline"End If Response.Write(strMessage)Next
 
Hope this helps! Please do not forget to mark the helpful post(s) as Answer so future readers know what solved your problem.

MY is requiring declaration and where is it to be declared?

IfMy.Computer.Network.Ping(arrServers(intCount))Then


Are you using ASP 1.x or 2.0?
2.0

Well that is really strange, becuase My works just fine and I have tested it.

It should be an automatically inherited namespace. I guess the only thing I can suggest you to try it to put

Imports My

at the top of the code behind.

Also, are you using C#?


Heck no. I can't stand anything to do with C. LOL I am using VB.

It works to an extent. I have about 14 servers I do this and I want to be able to do:

XXX Online or XXX Offline

YYY Online or YY Offline

Right now it is accounting all of the being online becasue it is going to the first one.


Thanks,


I got it to work. I had to alter some of the code. I got rid of the arrays and the loop. I did use the rest of your coding. I appreciate your help.
Glad you got it working! Please mark the most helpful post(s) asAnswer for the sake of future readers. Thank you.