Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Saturday, March 24, 2012

passing variable value to method in .cs

I would like to set
errormessage and retrieve it in my method QWE()
It doesnt work. What am I doing wrong?

public class AppLogic
{
string errormessage ="We are sorry, DB Error try again later";

public static void QWE()
{
HttpContext.Current.Response.Write("<script type=text/javascript language=javascript>alert('" + errormessage +"');</script>");
}
}

Mate, How can we help you if you dont tell us what error message you get?

Try this though...

public string errormessage = errormessage ="We are sorry, DB Error try again later";


Embarrassed

CS0120: An object reference is required for the nonstatic field, method, or property 'AppLogic.errormessage'

public class AppLogic
{
publicstaticstring errormessage ="We are sorry, DB Error try again later";

public static void QWE()
{
HttpContext.Current.Response.Write("<script type=text/javascript language=javascript>alert('" +
AppLogic.errormessage +"');</script>");
}
}

static method can only manipulate static field.


lovely it works :)
thank you

Best to use getters and setters when passing information in vairable about your system.

//Delcare the variable as private.

#region Declerations

private

staticstring fromAddress =string.Empty;

#endregion

//Delcare the getters and setters as public

#region Properties

publicstaticstring FromAddress {get {return fromAddress; }set { fromAddress =value; } }

#endregion

Passing Variable to XSLT

I have a ASP.NET application written in VB.net 2003 with a form I am
using to create an export file. Using XslTransform class I have a form
that collects data and executes a stored procedure to pull information
from my SQL Database. I would like to include information from a
textbox on the form in the XSL stylesheet. Can some one please explain
how I can pull information from my code and pass it to the stylesheet?
Thanks
CharlesRead this: http://msdn2.microsoft.com/en-us/library/ts9by56w.aspx
<cbanks@.bjtsupport.com> wrote in message
news:1133885799.818228.237430@.g49g2000cwa.googlegroups.com...
>I have a ASP.NET application written in VB.net 2003 with a form I am
> using to create an export file. Using XslTransform class I have a form
> that collects data and executes a stored procedure to pull information
> from my SQL Database. I would like to include information from a
> textbox on the form in the XSL stylesheet. Can some one please explain
> how I can pull information from my code and pass it to the stylesheet?
> Thanks
> Charles
>
One thing that comes to mind, though I'm sure I'm overcomplicating
it... is to make the XSLT an aspx page (you can specify the
appropriatae content-type in the codebehind) and pass it a query
paramater (MyXslt.xsl.aspx?Id=7). I do this with my ECMAScript
(JavaScript) at times like "GetFirefoxSVGInformation.js.aspx?id=314"
This would work clientside, but should be close on serverside too.
Peter,
Thanks for the quick reply! I'll work with that information.
Charles
Being new to all of this, I need to ask one more question. Once the
variable is passed, how do I insert it into my xslt?
<xsl:for-each select="PrintChecks/tblChecks">
<xsl:text>TRANS CHECK </xsl:text>
<xsl:text></xsl:text><xsl:value-of select="fldFirstName"/>
<xsl:text> </xsl:text><xsl:value-of select="fldLastName"/>
var needs to go here
...
/xsl:for-each
Thanks again.
I was able to figure everything out thanks to the link Peter sent.
Just goes to show ya that a little help from some one in these groups
goes a long way!
Thanks again!
Charles

passing variable value to method in .cs

I would like to set
errormessage and retrieve it in my method QWE()
It doesnt work. What am I doing wrong?

public class AppLogic{string errormessage ="We are sorry, DB Error try again later";public static void QWE() { HttpContext.Current.Response.Write("<script type=text/javascript language=javascript>alert('" + errormessage +"');</script>"); }}

Can you give an example of the return? What is the result/output of running this?


I would like to set
errormessage

string errormessage ="We are sorry, DB Error try again later";
and retrieve it in my method QWE()

('" + errormessage +"')
It doesnt work. What am I doing wrong?

public class AppLogic
{
string errormessage ="We are sorry, DB Error try again later";

public static void QWE()
{
HttpContext.Current.Response.Write("<script type=text/javascript language=javascript>alert('" + errormessage +"');</script>");
}

Wednesday, March 21, 2012

Passsing a connection object

I have a class that creates a connection to the database. When I call this object from my aspx code behind to get a connection to the database I get an error.
Object reference not set to an instance of an object.
How can I pass a connction object back from a class to a aspx code behind.pls post some code so that we might see the problem ...
if an object is not marked as Shared, you need to instantiate it before calling any of its methods.

based on your error you may have something like this:

dim oConn as MyConnectionObject
dim something as string
something = oConn.GetConnString

this will fail

you need

dim oConn asNew MyConnectionObject
dim something as string
something = oConn.GetConnString

Friday, March 16, 2012

password fields

why is it that password fields:

<asp:TextBox Id="txtuserpassword1" TextMode="password" class="textbox" maxlength="20" Columns="15" Runat="Server" /><br
clear everytime validation kicks in or on page refreshes? Can this be stopped? Help!
Also, I can't auto-populate the password field uising a database value.

Help. Thanx.This is the default behavior. If password fields were to refresh, they would have to be stored in ViewState. Since ViewState is stored on the HTML rendered to the browser, the user can easily do a view source and have access to the password. This defeats the purpose of having the password masked.

There is no way to override this, unless you make a custom control, or some other work around.

hope this helps,
John

"Chris" wrote:

> why is it that password fields:
> <asp:TextBox Id="txtuserpassword1" TextMode="password" class="textbox" maxlength="20" Columns="15" Runat="Server" /><br>
> clear everytime validation kicks in or on page refreshes? Can this be stopped? Help!
> Also, I can't auto-populate the password field uising a database value.
> Help. Thanx.
ok, I can buy the "refresh" reason but what about setting to a value via a database call:

txtuserpassword1.Text = "" & memberdata("USER_PASSWORD")
txtuserpassword2.Text = "" & memberdata("USER_PASSWORD")

they won't populate, why?
thanx.

"John Sivilla" wrote:

> This is the default behavior. If password fields were to refresh, they would have to be stored in ViewState. Since ViewState is stored on the HTML rendered to the browser, the user can easily do a view source and have access to the password. This defeats the purpose of having the password masked.
> There is no way to override this, unless you make a custom control, or some other work around.
> hope this helps,
> John
> "Chris" wrote:
> > why is it that password fields:
> > <asp:TextBox Id="txtuserpassword1" TextMode="password" class="textbox" maxlength="20" Columns="15" Runat="Server" /><br>
> > clear everytime validation kicks in or on page refreshes? Can this be stopped? Help!
> > Also, I can't auto-populate the password field uising a database value.
> > Help. Thanx.
My guess is it's built into the design of the server control. It would
seem to be a security risk to allow prepopulating a password field.
Perhaps you could do a JavaScript kludge to work around it though if you
really had to.

Chris wrote:

>why is it that password fields:
><asp:TextBox Id="txtuserpassword1" TextMode="password" class="textbox" maxlength="20" Columns="15" Runat="Server" /><br>
>clear everytime validation kicks in or on page refreshes? Can this be stopped? Help!
>Also, I can't auto-populate the password field uising a database value.
>Help. Thanx.
asp.net clears password fields by default. to set the values in code behind
use the value attribute:

txtuserpassword1.Attributes.Add("value",myPassedValue);

-- bruce (sqlwork.com)

"Chris" <Chris@.discussions.microsoft.com> wrote in message
news:53BA7FBD-26A4-458A-BA32-0AB61190C1E6@.microsoft.com...
> why is it that password fields:
> <asp:TextBox Id="txtuserpassword1" TextMode="password" class="textbox"
maxlength="20" Columns="15" Runat="Server" /><br>
> clear everytime validation kicks in or on page refreshes? Can this be
stopped? Help!
> Also, I can't auto-populate the password field uising a database value.
> Help. Thanx.
This will work, but for security reasons, I would recommend not putting the
actual password value in there (as it can then become visible to the user if
they view source). Rather, I've often put in "********" as the value to
represent that something has been entered. The next time the user posts, if
that value matches, then I know they left it alone and the code responds
accordingly. Otherwise, they've made a change.

Ben Lucas
Lead Developer
Solien Technology, Inc.

"bruce barker" <nospam_brubar@.safeco.com> wrote in message
news:OOApwjbbEHA.368@.TK2MSFTNGP10.phx.gbl...
> asp.net clears password fields by default. to set the values in code
behind
> use the value attribute:
> txtuserpassword1.Attributes.Add("value",myPassedValue);
> -- bruce (sqlwork.com)
> "Chris" <Chris@.discussions.microsoft.com> wrote in message
> news:53BA7FBD-26A4-458A-BA32-0AB61190C1E6@.microsoft.com...
> > why is it that password fields:
> > <asp:TextBox Id="txtuserpassword1" TextMode="password" class="textbox"
> maxlength="20" Columns="15" Runat="Server" /><br>
> > clear everytime validation kicks in or on page refreshes? Can this be
> stopped? Help!
> > Also, I can't auto-populate the password field uising a database value.
> > Help. Thanx.

password fields

why is it that password fields:
<asp:TextBox Id="txtuserpassword1" TextMode="password" class="textbox" maxle
ngth="20" Columns="15" Runat="Server" /><br>
clear everytime validation kicks in or on page refreshes? Can this be stoppe
d? Help!
Also, I can't auto-populate the password field uising a database value.
Help. Thanx.This is the default behavior. If password fields were to refresh, they would
have to be stored in ViewState. Since ViewState is stored on the HTML rende
red to the browser, the user can easily do a view source and have access to
the password. This defeats
the purpose of having the password masked.
There is no way to override this, unless you make a custom control, or some
other work around.
hope this helps,
John
"Chris" wrote:

> why is it that password fields:
> <asp:TextBox Id="txtuserpassword1" TextMode="password" class="textbox" max
length="20" Columns="15" Runat="Server" /><br>
> clear everytime validation kicks in or on page refreshes? Can this be stop
ped? Help!
> Also, I can't auto-populate the password field uising a database value.
> Help. Thanx.
>
ok, I can buy the "refresh" reason but what about setting to a value via a d
atabase call:
txtuserpassword1.Text = "" & memberdata("USER_PASSWORD")
txtuserpassword2.Text = "" & memberdata("USER_PASSWORD")
they won't populate, why?
thanx.
"John Sivilla" wrote:

> This is the default behavior. If password fields were to refresh, they would have
to be stored in ViewState. Since ViewState is stored on the HTML rendered to the bro
wser, the user can easily do a view source and have access to the password. This def
eat
s the purpose of having the password masked.
> There is no way to override this, unless you make a custom control, or som
e other work around.
> hope this helps,
> John
> "Chris" wrote:
>
My guess is it's built into the design of the server control. It would
seem to be a security risk to allow prepopulating a password field.
Perhaps you could do a JavaScript kludge to work around it though if you
really had to.
Chris wrote:

>why is it that password fields:
><asp:TextBox Id="txtuserpassword1" TextMode="password" class="textbox" maxl
ength="20" Columns="15" Runat="Server" /><br>
>clear everytime validation kicks in or on page refreshes? Can this be stopp
ed? Help!
>Also, I can't auto-populate the password field uising a database value.
>Help. Thanx.
>
>
asp.net clears password fields by default. to set the values in code behind
use the value attribute:
txtuserpassword1.Attributes.Add("value",myPassedValue);
-- bruce (sqlwork.com)
"Chris" <Chris@.discussions.microsoft.com> wrote in message
news:53BA7FBD-26A4-458A-BA32-0AB61190C1E6@.microsoft.com...
> why is it that password fields:
> <asp:TextBox Id="txtuserpassword1" TextMode="password" class="textbox"
maxlength="20" Columns="15" Runat="Server" /><br>
> clear everytime validation kicks in or on page refreshes? Can this be
stopped? Help!
> Also, I can't auto-populate the password field uising a database value.
> Help. Thanx.
>
This will work, but for security reasons, I would recommend not putting the
actual password value in there (as it can then become visible to the user if
they view source). Rather, I've often put in "********" as the value to
represent that something has been entered. The next time the user posts, if
that value matches, then I know they left it alone and the code responds
accordingly. Otherwise, they've made a change.
Ben Lucas
Lead Developer
Solien Technology, Inc.
"bruce barker" <nospam_brubar@.safeco.com> wrote in message
news:OOApwjbbEHA.368@.TK2MSFTNGP10.phx.gbl...
> asp.net clears password fields by default. to set the values in code
behind
> use the value attribute:
> txtuserpassword1.Attributes.Add("value",myPassedValue);
> -- bruce (sqlwork.com)
> "Chris" <Chris@.discussions.microsoft.com> wrote in message
> news:53BA7FBD-26A4-458A-BA32-0AB61190C1E6@.microsoft.com...
> maxlength="20" Columns="15" Runat="Server" /><br>
> stopped? Help!
>
does the trick, thanx a lot!
"bruce barker" wrote:

> asp.net clears password fields by default. to set the values in code behin
d
> use the value attribute:
> txtuserpassword1.Attributes.Add("value",myPassedValue);
> -- bruce (sqlwork.com)
> "Chris" <Chris@.discussions.microsoft.com> wrote in message
> news:53BA7FBD-26A4-458A-BA32-0AB61190C1E6@.microsoft.com...
> maxlength="20" Columns="15" Runat="Server" /><br>
> stopped? Help!
>
>
good suggestions, I never thought of that!
"Ben Lucas" wrote:

> This will work, but for security reasons, I would recommend not putting th
e
> actual password value in there (as it can then become visible to the user
if
> they view source). Rather, I've often put in "********" as the value to
> represent that something has been entered. The next time the user posts,
if
> that value matches, then I know they left it alone and the code responds
> accordingly. Otherwise, they've made a change.
> Ben Lucas
> Lead Developer
> Solien Technology, Inc.
> "bruce barker" <nospam_brubar@.safeco.com> wrote in message
> news:OOApwjbbEHA.368@.TK2MSFTNGP10.phx.gbl...
> behind
>
>