Solved

enabling a button

Posted on 2004-10-15
30
353 Views
Last Modified: 2012-08-13
Hi, I have a button which is initially disable, how to i enable it when the user comes from another page.

eg. in  webform1, the button is disabled, but if the user is coming from webform2 it needs to be enabled.

Pls show in code exampls


thanks

SirReadAlot
0
Comment
Question by:SirReadAlot
  • 16
  • 12
  • 2
30 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 12320849
Hi SirReadAlot,

if you use Response.Redirect - you have to set a session variable where the user comes from
and in the webform1 you can do

if (Session["prevPage"].ToString() == "webform2" )
 btn.Enabled = true;
else
 btn.Enabled = false;

Regards!
B..M
0
 

Author Comment

by:SirReadAlot
ID: 12320902
sorry my .net is ltd, this looks like c#

this is the code that causes the hyperlink mine is in vb

  Public Sub OnUpdate(ByVal e As DataGridCommandEventArgs)
        'Redirects to page to enable edit of User details selected
        Dim ID As Integer
        ID = dgEditUsers.DataKeys(e.Item.ItemIndex)
        Response.Redirect("Admin.aspx?ID=" & ID)

     End Sub
0
 

Author Comment

by:SirReadAlot
ID: 12320938
 Public Sub OnUpdate(ByVal e As DataGridCommandEventArgs)
        'Redirects to page to enable edit of User details selected
        Dim ID As Integer
        ID = dgEditUsers.DataKeys(e.Item.ItemIndex)
        Response.Redirect("Admin.aspx?ID=" & ID)

     End Sub
This hylinks nicelly to webform1, what do i do to enable the button when the user gets to webform1

thanks
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12321030
Public Sub OnUpdate(ByVal e As DataGridCommandEventArgs)
        'Redirects to page to enable edit of User details selected
        Dim ID As Integer
        ID = dgEditUsers.DataKeys(e.Item.ItemIndex)
        Session("AuthenticateUser") = "webform2"
        Response.Redirect("Admin.aspx?ID=" & ID)

     End Sub

in your webform1

If Session("AuthenticateUser").ToString() = "webform2" Then
  btn.Enabled = true
else
  btn.Enabled = false
End If

B..M
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12321204
You can also check out  'Request.UrlReferrer' property for this. That will save you from coding in different pages.

UrlReferrer: Gets information about the URL of the client's previous request that linked to the current URL.

Your code will be something like following
(I'm writting in C# but I guess it's easy to understand)
---------------------------------------------------------------------------------------------------------------------------------------
public void Page_Load(..)
{
   CheckUrl();
}

private void CheckUrl()
{
    string strUrl = Request.UrlReferrer.AbsoluteUri;  
    if( strUrl.ToLower().IndexOf("webform2") > -1 )
               btn.Enable = true;
     else
               btn.Enable = false;
}
---------------------------------------------------------------------------------------------------------------------------------------

-tushar
0
 

Author Comment

by:SirReadAlot
ID: 12321218
to clarify,

what is  "AuthenticateUser", b/c its actually throwing an exception.

We haven't assigned any login yet, am just jumping from page to page. so what should i use in plase of authenticateuser
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12321275
an exception ?? what exception - it is just a key in the session collection

tusharashah, if you use Response.Redirect i don't think you can use the UrlReferer - may be if you use Server.Transfer method

B..M
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12321585
Oh yes... Response.Redirect will not set UrlReferrer.

You'll only be able to use it if you are using HyperLinks or Server.Transver.

Thanks B..M!

-tusahr
0
 

Author Comment

by:SirReadAlot
ID: 12324078
Guys, pls this isn't working.

this is what i have in the page load of the form whiose button i want to enable --

If Session("AuthenticateUser").ToString() = "webform3" Then
            Button1.Enabled = True
        Else
            Button1.Enabled = False
        End If
--------------------------------------------------------------

and this is what i have in the webform, where the user will be clicking on to get to the above

  Session("AuthenticateUser") = "webform3"
        Response.Redirect("Adminadd.aspx?ID=" & ID)


thanks
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324133
and waht actually happened ? do you receive any errors ?

B..M
0
 

Author Comment

by:SirReadAlot
ID: 12324186
no errors, instead the button is still disabled.




0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324207
can you debug and see what is the value of Session("AuthenticateUser") when you go from the page "webform3"
B..M
0
 

Author Comment

by:SirReadAlot
ID: 12324283
Sorry, no errors but the button is enabled when i get in from webform3,

am gonna do the debug and find what the value is
0
 

Author Comment

by:SirReadAlot
ID: 12324322
any other method??
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324349
have you debug your code ? what is the value of Session("AuthenticateUser") when you go from the page "webform3" to webform1 ???
B..M
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:SirReadAlot
ID: 12324376
VALUE IS  webform3
0
 

Author Comment

by:SirReadAlot
ID: 12324415
is that right??
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324448
try to replace this
If Session("AuthenticateUser").ToString() = "webform3" Then
            Button1.Enabled = True
        Else
            Button1.Enabled = False
        End If

with

If Session("AuthenticateUser").ToString() = "webform3" Then
            Button1.Visible = True
        Else
            Button1.Visible = False
        End If

B..M
0
 

Author Comment

by:SirReadAlot
ID: 12324515
still not working, i apprieciate your efforts!!!!
its still not working

Lets start from the top
this rides in the page load webform1, the destination form with the button, right?

If Session("AuthenticateUser").ToString() = "webform3" Then
            Button1.Visible = True
        Else
            Button1.Visible = False
        End If
 
this is in the button click event of the departing form webform3

  Session("AuthenticateUser") = "webform3"
        Response.Redirect("webform1.aspx?ID=" & ID)
0
 

Author Comment

by:SirReadAlot
ID: 12324560
1)It should be disabled when I just build and browse form1.

2)It should be enabled when I gain assess to webform1 from webform3.

right now it is achieving step 2.
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324572
yes, and if you come from webform3 the button will be visible, if you come from ( for example ) webform2 the button will not be visible

B..M
0
 

Author Comment

by:SirReadAlot
ID: 12324716
nope,  when i build and browse the form where the button resides in, it shouldn't be visible. ...but it is. but from webform3 it is visible.
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324726
but in the other form what do you set to Session("AuthenticateUser") = "webform3" ?

B..M
0
 

Author Comment

by:SirReadAlot
ID: 12324761
If Session("AuthenticateUser").ToString() = "webform3" Then
            Button1.Visible = True
        Else
            Button1.Visible = False
        End If
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 250 total points
ID: 12324776
no man

webform3
Session("AuthenticateUser") = "webform3"
        Response.Redirect("webform1.aspx?ID=" & ID)

webform2
Session("AuthenticateUser") = "webform2"
        Response.Redirect("webform1.aspx?ID=" & ID)

webform1

If Session("AuthenticateUser").ToString() = "webform3" Then
            Button1.Visible = True
        Else
            Button1.Visible = False
        End If


when you come from webform3 the button will be visible
when you come from webform2 the button will not be visible

B..M
0
 

Author Comment

by:SirReadAlot
ID: 12324820
Yes it works, I thought along to prove that it works I have to build and browse webfom3,.. Is it possible to build and browse webform3 and not see the button??
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324847
if you start the application for first time
0
 

Author Comment

by:SirReadAlot
ID: 12324867
thanks you have been very generous your knownledge. Unlike my colleague.

Hope to be like you guys one day.


thank you very much.

I'll be back.
0
 

Author Comment

by:SirReadAlot
ID: 12327244
why, is it on form load, webform1 throws any exception of "Object reference not set to an instance of an object."

this line is highlighted "If Session("AuthenticateUser").ToString() = "webform3" Then"


and this is the actual code=--------

If Session("AuthenticateUser").ToString() = "webform1" Then
            Button1.Visible = True
        Else
            If Session("AuthenticateUser").ToString() = "webform3" Then
                Button1.Visible = True

            End If
            Button1.Visible = False
        End If


0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12329247
It is because you don't check
If Not Session("AuthenticateUser") = Nothing Then

B..M
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now