Hi
I want to pass these 2 fields. How i should pass in below code to User Control. Please help me
Int32 recno = Convert.ToInt32(Common.CommonFunction.EncodePasswordToBase64(row["docno"].ToString()));
string sp = Common.CommonFunction.EncodePasswordToBase64("sp_Inv");
string deleteAttributes = Status == "Blocked" ? "style='pointer-events: none; opacity: 0.5;' onclick='return false;'" : "data-toggle='modal' data-target='#modal_Delete' onclick='BindData(this);'";
htmlTable.Append($"");
Thanks
Aman GuptaPosted Aug 28, 2024, 4:24 PM
Hi Ramco,
To pass the two fields recno and sp to a User Control in your ASP.NET WebForm, you need to follow a few steps. Assuming you're trying to pass these values to a user control when the delete button is clicked, you'll typically use either a QueryString, Session, or ViewState depending on how you're handling the request.
1. Using QueryString (If the values are needed in a different page or user control):
You can append these values as query string parameters in the URL when you're invoking the user control or the page where the user control is included.
Then in the user control, you can retrieve these values:
2. Using Session (If you don't want to expose these values in the URL):
Store these values in a session before navigating to the user control.
In the user control, retrieve these session values:
3. Passing Values Directly to User Control:
If the user control is on the same page, you can pass these values directly as properties.
In the page where the control is used:
In the user control:
4. JavaScript (For Client-Side Handling):
If you want to handle this client-side using JavaScript and pass values back to the server later:
Then in JavaScript, you can handle the click event:
Later, you can pass these values back to the server via an AJAX request or form submission.
Choosing the Right Method:
QueryString is simple but exposes data in the URL.
Session is secure but shared across the user's session.
Direct Properties is ideal when you are working within the same page.
JavaScript Data Attributes are useful when you need to handle data on the client side first.
Choose the method that best suits your application's architecture and security requirements.
Jignesh KumarPosted Aug 28, 2024, 9:47 AM
Hello Raco,
using javascript you can do that,
in your main page, Find User control and create SetData method and pass that values,
In your user control,
Ramco RamcoPosted Aug 28, 2024, 9:27 AM
Hi Jignesh
I want to access these 2 values in User Control. I have made below changes in Html
Thanks
Jignesh KumarPosted Aug 28, 2024, 9:16 AM
Hello Ramco,
You can do below change in htmlTable,
Using Query string you can pass in jquery/Javascript,
in you page :
Ramco RamcoPosted Aug 28, 2024, 9:16 AM
Hi Gowtham
How.
Regards
Gowtham CpPosted Aug 28, 2024, 9:10 AM
To pass parameters to a User Control in a concise way, you can encode them and include them directly in the HTML attributes. Here’s how you can do it:
1. Encode Parameters
2. Generate HTML with Parameters
3. JavaScript Function
Explanation:
Encode the
recnoandspparameters for safe inclusion in JavaScript, and embed them directly into the HTML. TheBindDatafunction will then handle these parameters when the user interacts with the element.