Showing posts with label ideas. Show all posts
Showing posts with label ideas. Show all posts

Saturday, March 31, 2012

Set a session variable to pre defined value

I just want to set a sesison variable to a defined value when a page loads, I've tried the following but it doesn't seem to work. Any ideas where I'm going wrong?

<%# Session("var1") = "abc" %
Thanks

Julian ParkinsonYou've used adata binding expression, so it will only be called when DataBind() is called on the Page.

I think you want to use aninline code expression instead:

<% Session("var1") = "abc" %>

Hi,

You need to put the Session variable in the Page_Load like this:


if(!Page.IsPostBack)
{

Session["Name"] = "NewValue";
Response.Redirect("Mynewpage.aspx");

}

And then in the Mynewpage.aspx you can recieve the session using this code in the Page_Load with not postback.

if(Session["Name"] == null )
Response.Redirect("LoginPage.aspx");

else
Label1.Text = Session["Name"].ToString();


Dan,

Cheers for that. I just needed the remove the hash!! Duhh!

I'm moving from asp vb to asp.net vb and i'm finding it strange, some stuff is the same, some isn't sometimes I can't see the wood for the trees.

Thanks again.

Saturday, March 24, 2012

Set Focus on txt box within an user control

I am try to find a way to set focus on the txt box that is in an user control I create, any ideas about this?

ThanksYou can do this using Javascript.

Thanks,
Sridhar!!
Thanks, How? this text box is in the user control, I know how to use JavaScript to set Focus if the control is a server control but not this one.
You just need to make sure that you use the full client ID of the textbox. You could do this by hard-coding the ID of the user control appended to the ID of the textbox, or you could just get the ClientID of the textbox and pass that to your client script.
Hi Penghao98,

How about usingthis control from Meta builders which will essentially write javascript for you :)

HTH
Thanks, do you think you can give me a little example of it?
Hmm. I am not really for using a third party control, for as simple as this. You should identify your textbox inside the user control (in javascript) and set the focus after the page has loaded.

Lets say your user control id is "uc1"
and id of the textbox inside the "uc1" user control is "txt1"

You should be able to set the focus as

document.getElementById("uc1:txt1").focus();

Remember to place this code after the controls on the form has been loaded. May be after the closing form tag "</form>" in the html
Actually, I believe that would be

document.getElementById("uc1_txt1").focus();

(note the underscore instead of colon)
Yeah Peter is correct it should be

document.getElementById("uc1_txt1").focus();
oops. Sorry for the mistake. It should be underscore. Thanks for correcting me guys
Check out this :view post 821121

regards

Tuesday, March 13, 2012

set multiview active on selection asp:menu item

I have an asp:menu with items in it and a multiview. I want to set the multiview pane depending on which menu item is clicked. Any ideas?

thanks

Andrew

Hi, ajw

Here are references :

http://blogs.vbcity.com/mcintyre/archive/2006/11/07/6773.aspx

http://www.codeproject.com/aspnet/TabControl.asp

Hope this helps


I already have a menu set up which I want to use.

So if i have an on menu clicked method then in that I want to set the multiview pane of (whatever) to active depending on which menu item is clicked.

Thanks for the help

Andrew


ajw:

I already have a menu set up which I want to use.

So if i have an on menu clicked method then in that I want to set the multiview pane of (whatever) to active depending on which menu item is clicked.

Thanks for the help

Andrew

Hi, andrew

This is for you:

ProtectedSub Menu1_MenuItemClick(ByVal senderAsObject,ByVal eAs MenuEventArgs)Handles Menu1.MenuItemClick

MultiView1.ActiveViewIndex = Int32.Parse(e.Item.Value)

Menu1.Items(0).ImageUrl ="~/Images/HomeDisabled.jpg"

Menu1.Items(1).ImageUrl ="~/Images/ProductsDisabled.jpg"

Menu1.Items(2).ImageUrl ="~/Images/SupportDisabled.jpg"

Menu1.Items(3).ImageUrl ="~/Images/HelpDisabled.jpg"

SelectCase e.Item.Value

Case 0

Menu1.Items(0).ImageUrl ="~/Images/HomeEnabled.jpg"

Case 1

Menu1.Items(1).ImageUrl ="~/Images/ProductsEnabled.jpg"

Case 2

Menu1.Items(2).ImageUrl ="~/Images/SupportEnabled.jpg"

Case 3

Menu1.Items(3).ImageUrl ="~/Images/HelpEnabled.jpg"

EndSelect

EndSub

//////////////////////////////////////

Please tell us if there is something else you have. Thanks

Hope this helps.


Can i use a query string ? e.g. mypage.aspx?multiview=1 because the menu I have is in a masterpage and the multiview is in a content page. I have used your examples to create a working model using that method. Thankyou.

Andrew


Can i use a query string ? e.g. mypage.aspx?multiview=1 because the menu I have is in a masterpage and the multiview is in a content page. I have used your examples to create a working model using that method. But have a problem in my scenario. Thankyou.

Andrew


Hi, Andrew

Are you looking this method?

protectedvoidXXX_SelectedIndexChanged(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = Convert.ToInt32(XXX.SelectedValue);
}

Hope this helps.


It doesnt work because it always says either the menu1 or the multiview1 is undeclared because the menu is on the masterpage and the multiview on the content page.

If I have a url of

e.gg

http://www.abtecnet.com/services.aspx?view=1

http://www.abtecnet.com/services.aspx?view=2

etc

Then cant I get the query string with Response.Write(Request.QueryString("view"))

And then somehow use that number to set the active index of the multiview?

Cheers

Andrew


If Ive got

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim viewstring As String
viewstring = Request.QueryString("view")

servicemultiview.setactiveindex()
End Sub

how do I set the active index to the value of the query string based on above?

Thanks

Andrew


Done it now

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim viewstring As Int32
viewstring = Request.QueryString("view")
servicemultiview.ActiveViewIndex = viewstring
End Sub