Showing posts with label guid. Show all posts
Showing posts with label guid. Show all posts

Wednesday, March 21, 2012

Passing a GUID to another page

I would like to figure out the solution to this problem.

Compilation Error

Description:An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message:BC30311: Value of type 'System.Guid' cannot be converted to 'String'.

Source Error:

Line 348: <asp:TemplateField SortExpression="avatar">Line 349:<ItemTemplate>Line 350:<asp:Image ID="Image1" runat="server" ImageUrl='<%# "AvatarImagefetch.ashx?UserName=" & CStr(new Guid(Eval("UserID").ToString()))) %>'/>Line 351:</ItemTemplate>Line 352:

Now I have tried several variations to this theme.

Basically I want to convert "USERID" which is a GUID to a String before passing it to another page.

This is part of a Gridview.

Try this for ImageUrl (I am assuming you are using VB.NET from CStr)

<%# String.Concat("AvatarImagefetch.ashx?Username=", Eval("UserID"))%>
You don't need to cast Eval("UserID") as a Guid, you can leave it is an object because if it is a Guid you will just end up turning it back into a string.

Hi Kevin,

Thanks for the tip, I was reaserching this prior to your reply and found the following to work:

<

ItemTemplate>

<

asp:ImageID="Image1"runat="server"ImageUrl='<%# "AvatarImagefetch.ashx?MemberId=" & DataBinder.Eval(Container.DataItem,"UserId").ToString %>'/>

</

ItemTemplate>

I think you need the .ToString for it to be passed as a String.


I used String.Concat, and Concat can accept object and will automatically convert them to a string.

That is excellent tip, thanks once again Kevin.

passing a Guid to a button class

Hi i have a linkbutton created with C# that needs to call a class and pass a guid through to that class i have tried to use

public void buttonClass(string guid,object sender,Eventargs e)
but it does work i get an error so how do i pass a guid to this class form my button ( code below)

1//button class2public void prodAdd(object sender, EventArgs e)3 {4 checkoutFunctions cartAdd =new checkoutFunctions();5string userGuid = cartAdd.userFind(HttpContext.Current.User.Identity.Name);6 cartAdd.addItem(prodGuid, userGuid);7 Response.Redirect("cart.aspx");8 }910// BUtton generator11 mediaSelect.Controls.Add(new LiteralControl("<a href='#' onClick=\"flashshowHide('" + mediaId + "')\">" + medRead["media_name"].ToString().Replace("#@dotnet.itags.org.","'") +"<span class='prevBut'>(preview)</span></a>"));12 Button buyProd =new Button();13 buyProd.Text = ("Download for £" + medRead["media_price"].ToString());14 buyProd.Click +=new EventHandler(prodAdd);15 mediaSelect.Controls.Add(buyProd);16 mediaSelect.Controls.Add(new LiteralControl("<br/>"));
Thanks
Dan 

I think you must be missing something here conceptually. The prodAdd isnt a button class, it's an event handler that you're wiring up to handle the click event of your dynamically created button. That set of code will run only when the button is clicked. If you need to pass a GUID to it, pass it from wherever it was clicked at, not when the button is created.


yes ok but how do i set it to send the guid to the class when it is clicked


It's not a class - it's an event handler. You are going to have issues till you can get your terminology correct.

Try

buyProd.commandArgument = yourGUID

then in your event handler you can get the guid by using

e.commandArgument

passing a GUID in the querystring

I need to pass a GUID into a page via the QueryString. If I do:

Dim myGUID as GUID
GUID = Request.QueryString("myGUID")

It won't run, and says that a value type of string cannot be converted to a GUID. I can't retype myGUID as a string, because I use it in a SQL Server Database call...It yells at me if try to do a query with it in there.

Am I doing something wrong? or is there just no way to pass a GUID through the querystring?

ThanksIf you pass the value on the url it will be in a string format. The following worked for me. Maybe this will help.

select * from table1 where uniqueID = cast('{5BEEAA61-394B-44F6-9AC8-A6EA5FC99490}' as uniqueidentifier)
You need to do the following:

Dim MyGuid As Guid = New Guid(Request.QueryString("myGuid"))