Click here to Skip to main content
15,886,095 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have created a asp.net web application for that i am having two asp.net buttons in same page. First button for inserting the data and the second button for updating the data in SQL Server. Insertion part is done and creating an id. This id is Uniqueidentifer. I want that id when second click event generated how to achieve this please anybody give me the solution

What I have tried:

i have tried viewstate in first button and i tried to achieve that viewstate id to second but it is creating another id not the previous id that was created when first button click event fires. Not only viewstate i have tried with session also but no use. i will post with session object please help me to solve this issue anybody. Thanks in advance

This is first button click event created session
Session["ExamID"] = Guid.NewGuid();


This is second button click event fires
ObjExamBO.ExamID = (Guid)Session["ExamID"];
Posted
Updated 11-Dec-18 6:15am
Comments
Member 8583441 7-Dec-18 1:10am    
This page is not in master page
alexvw 7-Dec-18 12:09pm    
Hi there,

Is there a particular reason you are trying to capture the GUID object per se, instead of just its string representation?

Also, you ObjExamBO.ExamId property, what type is it? both of them should be the same.

Try:

Session["ExamID"] = Guid.NewGuid().ToString();

ObjExamBO.ExamID = (string)Session["ExamID"];

By the way, it would be better if you share your page markup/code behind; if for some reason you are clearing that session variable in between, there is no way for anybody to see it.

Cheers!
Member 8583441 7-Dec-18 15:14pm    
Both of them are in NullableGuid Property. But i have tried a lot spending more time with it and then finally i decided to create a new web page in this page i am passing query string and that querystring is given the property and the desired output has appeared. Thanks for your valuable suggestions

Have you tried using a HiddenField in your page? You can save the Guid ID as a plain string into that.
 
Share this answer
 
Comments
Vincent Maverick Durano 10-Dec-18 8:08am    
But storing them in a HiddenField is the same as storing them in ViewState.
Member 8583441 10-Dec-18 8:43am    
i have created hiddenfield and storing that value in hidden field. But no output so, that's why i created a new web page in this web page i require id to passed from previous page this is done with storing value in request.querystring and the output is executed as expected thank you all for giving me the solutions
Vincent Maverick Durano 10-Dec-18 18:33pm    
Are you saying you got it resolved now?
Member 8583441 10-Dec-18 23:37pm    
yes sir by using request.querystring. I doesn't know whether it is correct way or not
Vincent Maverick Durano 11-Dec-18 7:15am    
Querystring will expose the value in the URL.
I don't think using querystring is a good idea. However, i tried this scenario and it worked for me. I added 2 buttons and labels. On button 1 click, i generated a guid and stored it in a session variable and set it as text of label 1 and on click of 2nd button, i get the guid value from session and set it as label 2 text. In the output i can see both guids having same value. Here is the code.

C#
protected void FirstButton_Click(object sender, EventArgs e)
	{
		var guid = Guid.NewGuid();
		LblFirst.Text = guid.ToString();
		Session["Guid"] = guid.ToString();
	}

	protected void SecondButton_Click(object sender, EventArgs e)
	{
		var guid = Convert.ToString(Session["Guid"]);
		Label1.Text = guid;
	}
 
Share this answer
 
Comments
Member 8583441 13-Dec-18 1:37am    
thanks very much sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900