Solved

enabling a button

Posted on 2004-10-15
30
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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